diff --git a/crates/rustc_plugin/Cargo.toml b/crates/rustc_plugin/Cargo.toml index 39d4bffde..be3b83a88 100644 --- a/crates/rustc_plugin/Cargo.toml +++ b/crates/rustc_plugin/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc_plugin" -version = "0.12.0-nightly-2024-12-15" +version = "0.13.0-nightly-2025-03-03" edition = "2021" authors = ["Will Crichton "] description = "A framework for writing plugins that integrate with the Rust compiler" diff --git a/crates/rustc_plugin/examples/print-all-items/Cargo.toml b/crates/rustc_plugin/examples/print-all-items/Cargo.toml index 4235b954b..00dcde3be 100644 --- a/crates/rustc_plugin/examples/print-all-items/Cargo.toml +++ b/crates/rustc_plugin/examples/print-all-items/Cargo.toml @@ -8,6 +8,6 @@ rustc_private = true [dependencies] rustc_plugin = { path = "../.." } -env_logger = "0.10" +env_logger = {version = "0.10", default-features = false} clap = {version = "4.4", features = ["derive"]} serde = {version = "1", features = ["derive"]} \ No newline at end of file diff --git a/crates/rustc_plugin/examples/print-all-items/rust-toolchain.toml b/crates/rustc_plugin/examples/print-all-items/rust-toolchain.toml index 2451c2f1d..be68a3656 100644 --- a/crates/rustc_plugin/examples/print-all-items/rust-toolchain.toml +++ b/crates/rustc_plugin/examples/print-all-items/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-12-15" +channel = "nightly-2025-03-02" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/crates/rustc_plugin/examples/print-all-items/src/lib.rs b/crates/rustc_plugin/examples/print-all-items/src/lib.rs index 7022fb7e8..340bf172f 100644 --- a/crates/rustc_plugin/examples/print-all-items/src/lib.rs +++ b/crates/rustc_plugin/examples/print-all-items/src/lib.rs @@ -3,6 +3,7 @@ #![feature(rustc_private)] extern crate rustc_driver; +extern crate rustc_hir; extern crate rustc_interface; extern crate rustc_middle; extern crate rustc_session; @@ -10,6 +11,10 @@ extern crate rustc_session; use std::{borrow::Cow, env, process::Command}; use clap::Parser; +use rustc_hir::{ + intravisit::{self, Visitor}, + Item, +}; use rustc_middle::ty::TyCtxt; use rustc_plugin::{CrateFilter, RustcPlugin, RustcPluginArgs, Utf8Path}; use serde::{Deserialize, Serialize}; @@ -61,15 +66,16 @@ impl RustcPlugin for PrintAllItemsPlugin { compiler_args: Vec, plugin_args: Self::Args, ) -> rustc_interface::interface::Result<()> { - let mut callbacks = PrintAllItemsCallbacks { args: plugin_args }; - let compiler = rustc_driver::RunCompiler::new(&compiler_args, &mut callbacks); - compiler.run(); + let mut callbacks = PrintAllItemsCallbacks { + args: Some(plugin_args), + }; + rustc_driver::run_compiler(&compiler_args, &mut callbacks); Ok(()) } } struct PrintAllItemsCallbacks { - args: PrintAllItemsPluginArgs, + args: Option, } impl rustc_driver::Callbacks for PrintAllItemsCallbacks { @@ -82,7 +88,7 @@ impl rustc_driver::Callbacks for PrintAllItemsCallbacks { tcx: TyCtxt<'_>, ) -> rustc_driver::Compilation { // We call our top-level function with access to the type context `tcx` and the CLI arguments. - print_all_items(tcx, &self.args); + print_all_items(tcx, self.args.take().unwrap()); // Note that you should generally allow compilation to continue. If // your plugin is being invoked on a dependency, then you need to ensure @@ -92,21 +98,29 @@ impl rustc_driver::Callbacks for PrintAllItemsCallbacks { } } -// The core of our analysis. It doesn't do much, just access some methods on the `TyCtxt`. +// The core of our analysis. Right now it just prints out a description of each item. // I recommend reading the Rustc Development Guide to better understand which compiler APIs // are relevant to whatever task you have. -fn print_all_items(tcx: TyCtxt, args: &PrintAllItemsPluginArgs) { - let hir = tcx.hir(); - for item_id in hir.items() { - let item = hir.item(item_id); +fn print_all_items(tcx: TyCtxt, args: PrintAllItemsPluginArgs) { + tcx.hir_visit_all_item_likes_in_crate(&mut PrintVisitor { args }); +} + +struct PrintVisitor { + args: PrintAllItemsPluginArgs, +} + +impl Visitor<'_> for PrintVisitor { + fn visit_item(&mut self, item: &Item) -> Self::Result { let mut msg = format!( "There is an item \"{}\" of type \"{}\"", item.ident, item.kind.descr() ); - if args.allcaps { + if self.args.allcaps { msg = msg.to_uppercase(); } println!("{msg}"); + + intravisit::walk_item(self, item) } } diff --git a/crates/rustc_plugin/src/driver.rs b/crates/rustc_plugin/src/driver.rs index 4c93beb4c..f9ea4dbc6 100644 --- a/crates/rustc_plugin/src/driver.rs +++ b/crates/rustc_plugin/src/driver.rs @@ -152,7 +152,7 @@ pub fn driver_main(plugin: T) { log::debug!("Running plugin..."); let plugin_args: T::Args = serde_json::from_str(&env::var(PLUGIN_ARGS).unwrap()).unwrap(); - plugin.run(args, plugin_args) + plugin.run(args, plugin_args).unwrap(); } else { log::debug!( "Running normal Rust. Relevant variables:\ @@ -161,8 +161,7 @@ run_on_all_crates={run_on_all_crates}, \ primary_package={primary_package}, \ is_target_crate={is_target_crate}" ); - rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); - Ok(()) + rustc_driver::run_compiler(&args, &mut DefaultCallbacks); } })) } diff --git a/crates/rustc_utils/Cargo.toml b/crates/rustc_utils/Cargo.toml index cd71402e8..ea7b6aea5 100644 --- a/crates/rustc_utils/Cargo.toml +++ b/crates/rustc_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc_utils" -version = "0.12.0-nightly-2024-12-15" +version = "0.13.0-nightly-2025-03-03" edition = "2021" authors = ["Will Crichton "] description = "Utilities for working with the Rust compiler" @@ -27,7 +27,7 @@ serde = {version = "1", features = ["derive"], optional = true} textwrap = {version = "0.16", optional = true} regex = {version = "1", optional = true} ts-rs = {version = "7", optional = true} -indexical = {version = "0.3.1", default-features = false, features = ["rustc"], optional = true} +indexical = {version = "0.7.0", default-features = false, features = ["rustc"], optional = true} [dev-dependencies] rustc_utils = {path = ".", features = ["test"]} diff --git a/crates/rustc_utils/src/lib.rs b/crates/rustc_utils/src/lib.rs index f9c4fad00..e5d8efc56 100644 --- a/crates/rustc_utils/src/lib.rs +++ b/crates/rustc_utils/src/lib.rs @@ -41,6 +41,7 @@ )] extern crate either; +extern crate rustc_abi; extern crate rustc_borrowck; extern crate rustc_data_structures; extern crate rustc_driver; @@ -50,6 +51,7 @@ extern crate rustc_hir; extern crate rustc_index; extern crate rustc_infer; extern crate rustc_interface; +extern crate rustc_lint_defs; extern crate rustc_macros; extern crate rustc_middle; extern crate rustc_mir_dataflow; diff --git a/crates/rustc_utils/src/mir/body.rs b/crates/rustc_utils/src/mir/body.rs index 2298530d4..523452e46 100644 --- a/crates/rustc_utils/src/mir/body.rs +++ b/crates/rustc_utils/src/mir/body.rs @@ -137,7 +137,7 @@ impl<'tcx> BodyExt<'tcx> for Body<'tcx> { fn source_info_to_hir_id(&self, info: &SourceInfo) -> HirId { let scope = &self.source_scopes[info.scope]; - let local_data = scope.local_data.as_ref().assert_crate_local(); + let local_data = scope.local_data.as_ref().unwrap_crate_local(); local_data.lint_root } diff --git a/crates/rustc_utils/src/mir/borrowck_facts.rs b/crates/rustc_utils/src/mir/borrowck_facts.rs index bc1517afa..b7b3e4be6 100644 --- a/crates/rustc_utils/src/mir/borrowck_facts.rs +++ b/crates/rustc_utils/src/mir/borrowck_facts.rs @@ -108,17 +108,17 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &BorrowCheckResult<'_> { /// Note that as of May 2022, Polonius can be *very* slow for large functions. /// It may take up to 30 seconds to analyze a single body with a large CFG. #[allow(clippy::needless_lifetimes)] -pub fn get_body_with_borrowck_facts<'tcx>( - tcx: TyCtxt<'tcx>, +pub fn get_body_with_borrowck_facts( + tcx: TyCtxt<'_>, def_id: LocalDefId, -) -> &'tcx BodyWithBorrowckFacts<'tcx> { +) -> &BodyWithBorrowckFacts<'_> { let _ = tcx.mir_borrowck(def_id); MIR_BODIES.with(|cache| { let body = cache.get(&def_id, |_| panic!("mir_borrowck override should have stored body for item: {def_id:?}. Are you sure you registered borrowck_facts::override_queries?")); unsafe { std::mem::transmute::< &BodyWithBorrowckFacts<'static>, - &'tcx BodyWithBorrowckFacts<'tcx>, + &BodyWithBorrowckFacts<'_>, >(body) } }) diff --git a/crates/rustc_utils/src/mir/control_dependencies.rs b/crates/rustc_utils/src/mir/control_dependencies.rs index 0587d1473..f0d16b00d 100644 --- a/crates/rustc_utils/src/mir/control_dependencies.rs +++ b/crates/rustc_utils/src/mir/control_dependencies.rs @@ -13,7 +13,7 @@ use rustc_data_structures::graph::{ DirectedGraph, Predecessors, StartNode, Successors, }; use rustc_index::{ - bit_set::{BitSet, SparseBitMatrix}, + bit_set::{DenseBitSet, MixedBitSet, SparseBitMatrix}, Idx, }; use smallvec::SmallVec; @@ -21,7 +21,7 @@ use smallvec::SmallVec; struct ReversedGraph<'a, G: ControlFlowGraph> { graph: &'a G, exit: G::Node, - unreachable: BitSet, + unreachable: MixedBitSet, } impl DirectedGraph for ReversedGraph<'_, G> { @@ -76,7 +76,7 @@ impl PostDominators { let mut reversed = ReversedGraph { graph, exit, - unreachable: BitSet::new_empty(num_nodes), + unreachable: MixedBitSet::new_empty(num_nodes), }; let reachable = iterate::post_order_from(&reversed, exit); @@ -194,7 +194,7 @@ impl ControlDependencies { } /// Returns the set of all node that are control-dependent on the given `node`. - pub fn dependent_on(&self, node: Node) -> Option<&BitSet> { + pub fn dependent_on(&self, node: Node) -> Option<&DenseBitSet> { self.0.row(node) } } diff --git a/crates/rustc_utils/src/mir/location_or_arg.rs b/crates/rustc_utils/src/mir/location_or_arg.rs index e893c3f13..309b1c842 100644 --- a/crates/rustc_utils/src/mir/location_or_arg.rs +++ b/crates/rustc_utils/src/mir/location_or_arg.rs @@ -42,22 +42,15 @@ impl From for LocationOrArg { #[cfg(feature = "indexical")] pub mod index { - use indexical::{ - impls::RustcIndexSet, index_vec::define_index_type, IndexedDomain, IndexedValue, - ToIndex, - }; + use indexical::{bitset::rustc::IndexSet, define_index_type, IndexedDomain, ToIndex}; use super::*; define_index_type! { - pub struct LocationOrArgIndex = u32; + pub struct LocationOrArgIndex for LocationOrArg = u32; } - impl IndexedValue for LocationOrArg { - type Index = LocationOrArgIndex; - } - - pub type LocationOrArgSet = RustcIndexSet; + pub type LocationOrArgSet = IndexSet; pub type LocationOrArgDomain = IndexedDomain; pub struct CustomMarker; diff --git a/crates/rustc_utils/src/mir/place.rs b/crates/rustc_utils/src/mir/place.rs index 041e9715b..0e6e094e2 100644 --- a/crates/rustc_utils/src/mir/place.rs +++ b/crates/rustc_utils/src/mir/place.rs @@ -3,6 +3,7 @@ use std::{borrow::Cow, collections::VecDeque}; use log::{trace, warn}; +use rustc_abi::{FieldIdx, VariantIdx}; use rustc_data_structures::fx::{FxHashMap as HashMap, FxHashSet as HashSet}; use rustc_hir::def_id::DefId; use rustc_infer::infer::TyCtxtInferExt; @@ -15,7 +16,6 @@ use rustc_middle::{ traits::ObligationCause, ty::{self, AdtKind, Region, RegionKind, RegionVid, Ty, TyCtxt, TyKind, TypeVisitor}, }; -use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_trait_selection::traits::NormalizeExt; use rustc_type_ir::TypingMode; @@ -452,7 +452,7 @@ impl<'tcx, Dispatcher: RegionVisitorDispatcher<'tcx>> TypeVisitor> { fn visit_ty(&mut self, ty: Ty<'tcx>) { let tcx = self.tcx; - if self.ty_stack.iter().any(|visited_ty| ty == *visited_ty) { + if self.ty_stack.contains(&ty) { return; } @@ -556,7 +556,7 @@ impl<'tcx, Dispatcher: RegionVisitorDispatcher<'tcx>> TypeVisitor> _ if ty.is_primitive_ty() => {} _ => warn!("unimplemented {ty:?} ({:?})", ty.kind()), - }; + } // let inherent_impls = tcx.inherent_impls(self.def_id); // let traits = tcx.infer_ctxt().enter(|infcx| { @@ -764,7 +764,7 @@ fn main() { body_with_facts: &BodyWithBorrowckFacts<'tcx>, ) { let body = &body_with_facts.body; - let def_id = tcx.hir().body_owner_def_id(body_id).to_def_id(); + let def_id = tcx.hir_body_owner_def_id(body_id).to_def_id(); let p = Placer::new(tcx, body); let y = p.local("y").mk(); diff --git a/crates/rustc_utils/src/source_map/find_bodies.rs b/crates/rustc_utils/src/source_map/find_bodies.rs index 7b90783d0..9217ee881 100644 --- a/crates/rustc_utils/src/source_map/find_bodies.rs +++ b/crates/rustc_utils/src/source_map/find_bodies.rs @@ -13,32 +13,28 @@ struct BodyFinder<'tcx> { impl<'tcx> Visitor<'tcx> for BodyFinder<'tcx> { type NestedFilter = OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.tcx.hir() - } - fn visit_nested_body(&mut self, id: BodyId) { - let hir = self.nested_visit_map(); + let tcx = self.tcx; + let hir = tcx.hir(); // const/static items are considered to have bodies, so we want to exclude // them from our search for functions - if !hir - .body_owner_kind(hir.body_owner_def_id(id)) + if !tcx + .hir_body_owner_kind(tcx.hir_body_owner_def_id(id)) .is_fn_or_closure() { return; } - let body = hir.body(id); + let body = tcx.hir_body(id); self.visit_body(body); - let hir = self.tcx.hir(); - let span = hir.span_with_body(hir.body_owner(id)); + let span = hir.span_with_body(tcx.hir_body_owner(id)); trace!( "Searching body for {:?} with span {span:?} (local {:?})", self .tcx - .def_path_debug_str(hir.body_owner_def_id(id).to_def_id()), + .def_path_debug_str(tcx.hir_body_owner_def_id(id).to_def_id()), span.as_local(body.value.span) ); @@ -55,7 +51,7 @@ pub fn find_bodies(tcx: TyCtxt) -> Vec<(Span, BodyId)> { tcx, bodies: Vec::new(), }; - tcx.hir().visit_all_item_likes_in_crate(&mut finder); + tcx.hir_visit_all_item_likes_in_crate(&mut finder); finder.bodies } diff --git a/crates/rustc_utils/src/source_map/range.rs b/crates/rustc_utils/src/source_map/range.rs index dd3695e19..8350339f0 100644 --- a/crates/rustc_utils/src/source_map/range.rs +++ b/crates/rustc_utils/src/source_map/range.rs @@ -1,10 +1,10 @@ use std::{ cell::RefCell, collections::hash_map::Entry, default::Default, ffi::OsStr, - path::PathBuf, + path::PathBuf, sync::Arc, }; use anyhow::{bail, ensure, Context, Result}; -use rustc_data_structures::{fx::FxHashMap as HashMap, sync::Lrc}; +use rustc_data_structures::fx::FxHashMap as HashMap; use rustc_hir::{ intravisit::{self, Visitor}, BodyId, @@ -96,7 +96,7 @@ impl CharByteMapping { #[derive(Default)] pub struct RangeContext { filenames: IndexVec, - path_mapping: HashMap>, + path_mapping: HashMap>, char_byte_mapping: Cache, } @@ -120,11 +120,11 @@ impl Filename { } impl FilenameIndex { - pub fn find_source_file(self, source_map: &SourceMap) -> Result> { + pub fn find_source_file(self, source_map: &SourceMap) -> Result> { CONTEXT.with(|ctx| { let ctx = &mut *ctx.borrow_mut(); match ctx.path_mapping.entry(self) { - Entry::Occupied(entry) => Ok(Lrc::clone(entry.get())), + Entry::Occupied(entry) => Ok(Arc::clone(entry.get())), Entry::Vacant(entry) => { let files = source_map.files(); ensure!( @@ -164,7 +164,7 @@ impl FilenameIndex { ) })?; let file = source_map.get_source_file(rustc_filename).unwrap(); - entry.insert(Lrc::clone(&file)); + entry.insert(Arc::clone(&file)); Ok(file) } } @@ -345,9 +345,9 @@ fn qpath_to_span(tcx: TyCtxt, qpath: String) -> Result { impl<'tcx> Visitor<'tcx> for Finder<'tcx> { fn visit_nested_body(&mut self, id: BodyId) { - intravisit::walk_body(self, self.tcx.hir().body(id)); + intravisit::walk_body(self, self.tcx.hir_body(id)); - let local_def_id = self.tcx.hir().body_owner_def_id(id); + let local_def_id = self.tcx.hir_body_owner_def_id(id); let function_path = self .tcx .def_path(local_def_id.to_def_id()) @@ -363,7 +363,7 @@ fn qpath_to_span(tcx: TyCtxt, qpath: String) -> Result { qpath, span: None, }; - tcx.hir().visit_all_item_likes_in_crate(&mut finder); + tcx.hir_visit_all_item_likes_in_crate(&mut finder); finder .span .with_context(|| format!("No function with qpath {}", finder.qpath)) diff --git a/crates/rustc_utils/src/source_map/span.rs b/crates/rustc_utils/src/source_map/span.rs index b2fe0cf68..df5bb9f1b 100644 --- a/crates/rustc_utils/src/source_map/span.rs +++ b/crates/rustc_utils/src/source_map/span.rs @@ -74,7 +74,7 @@ impl SpanExt for Span { } } else { outer_spans.push(*self); - }; + } trace!("outer span for {self:?} with inner spans {child_spans:?} is {outer_spans:?}"); diff --git a/crates/rustc_utils/src/source_map/spanner/mod.rs b/crates/rustc_utils/src/source_map/spanner/mod.rs index 3302ceab9..368e5f25f 100644 --- a/crates/rustc_utils/src/source_map/spanner/mod.rs +++ b/crates/rustc_utils/src/source_map/spanner/mod.rs @@ -35,10 +35,10 @@ pub struct Spanner<'tcx> { impl<'tcx> Spanner<'tcx> { pub fn new(tcx: TyCtxt<'tcx>, body_id: BodyId, body: &Body<'tcx>) -> Self { let hir = tcx.hir(); - let hir_body = hir.body(body_id); - let owner = hir.body_owner(body_id); + let hir_body = tcx.hir_body(body_id); + let owner = tcx.hir_body_owner(body_id); let item_span = hir.span_with_body(owner); - let ret_span = hir.fn_decl_by_hir_id(owner).unwrap().output.span(); + let ret_span = tcx.hir_fn_decl_by_hir_id(owner).unwrap().output.span(); let mut spanner = Spanner { mir_spans: Vec::new(), @@ -119,8 +119,7 @@ impl<'tcx> Spanner<'tcx> { hir_spans.extend(spans); } - let hir = self.tcx.hir(); - let enclosing_hir = hir.parent_iter(hir_id).collect::>(); + let enclosing_hir = self.tcx.hir_parent_iter(hir_id).collect::>(); macro_rules! add_first_matching { ($p:pat) => { if let Some((id, _)) = enclosing_hir.iter().find(|(_, node)| matches!(node, $p)) { diff --git a/crates/rustc_utils/src/test_utils.rs b/crates/rustc_utils/src/test_utils.rs index 86518cfcf..94176579f 100644 --- a/crates/rustc_utils/src/test_utils.rs +++ b/crates/rustc_utils/src/test_utils.rs @@ -1,29 +1,33 @@ //! Running rustc and Flowistry in tests. use std::{ - fmt::Debug, fs, hash::Hash, io, panic, path::Path, process::Command, sync::LazyLock, + fmt::Debug, + fs, + hash::Hash, + io, panic, + path::Path, + process::Command, + sync::{Arc, LazyLock}, }; use anyhow::{anyhow, ensure, Context, Result}; use log::debug; +use rustc_abi::{FieldIdx, VariantIdx}; use rustc_borrowck::consumers::BodyWithBorrowckFacts; -use rustc_data_structures::{ - fx::{FxHashMap as HashMap, FxHashSet as HashSet}, - sync::Lrc, -}; -use rustc_hir::{BodyId, ItemKind}; +use rustc_data_structures::fx::{FxHashMap as HashMap, FxHashSet as HashSet}; +use rustc_driver::run_compiler; +use rustc_hir::BodyId; use rustc_middle::{ mir::{Body, HasLocalDecls, Local, Place}, ty::TyCtxt, }; use rustc_span::source_map::FileLoader; -use rustc_target::abi::{FieldIdx, VariantIdx}; use crate::{ mir::borrowck_facts, source_map::{ filename::{Filename, FilenameIndex}, - find_bodies::find_enclosing_bodies, + find_bodies::{find_bodies, find_enclosing_bodies}, range::{BytePos, ByteRange, CharPos, CharRange, ToSpan}, }, BodyExt, PlaceExt, @@ -39,7 +43,7 @@ impl FileLoader for StringLoader { Ok(self.0.clone()) } - fn read_binary_file(&self, path: &Path) -> io::Result> { + fn read_binary_file(&self, path: &Path) -> io::Result> { Ok(fs::read(path)?.into()) } } @@ -94,6 +98,7 @@ impl CompileBuilder { /// the provided closure pub fn compile(&self, f: impl for<'tcx> FnOnce(CompileResult<'tcx>) + Send) { let mut callbacks = TestCallbacks { + input: self.input.clone(), callback: Some(move |tcx: TyCtxt<'_>| f(CompileResult { tcx })), }; let args = [ @@ -101,7 +106,7 @@ impl CompileBuilder { DUMMY_FILE_NAME, "--crate-type", "lib", - "--edition=2021", + "--edition=2024", "-Zidentify-regions", "-Zmir-opt-level=0", "-Zmaximal-hir-to-mir-coverage", @@ -112,13 +117,11 @@ impl CompileBuilder { ] .into_iter() .map(str::to_owned) - .chain(self.arguments.iter().cloned()) + .chain(self.arguments.clone()) .collect::>(); rustc_driver::catch_fatal_errors(|| { - let mut compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks); - compiler.set_file_loader(Some(Box::new(StringLoader(self.input.clone())))); - compiler.run(); + run_compiler(&args, &mut callbacks); }) .unwrap(); } @@ -148,16 +151,8 @@ impl<'tcx> CompileResult<'tcx> { /// Assume that we compiled only one function and return that function's id and body. pub fn as_body(&self) -> (BodyId, &'tcx BodyWithBorrowckFacts<'tcx>) { let tcx = self.tcx; - let hir = tcx.hir(); - let body_id = hir - .items() - .find_map(|id| match hir.item(id).kind { - ItemKind::Fn(_, _, body) => Some(body), - _ => None, - }) - .unwrap(); - - let def_id = tcx.hir().body_owner_def_id(body_id); + let (_, body_id) = find_bodies(tcx).remove(0); + let def_id = tcx.hir_body_owner_def_id(body_id); let body_with_facts = borrowck_facts::get_body_with_borrowck_facts(tcx, def_id); debug!("{}", body_with_facts.body.to_string(tcx).unwrap()); (body_id, body_with_facts) @@ -172,7 +167,7 @@ impl<'tcx> CompileResult<'tcx> { let body_id = find_enclosing_bodies(tcx, target.to_span(tcx).unwrap()) .next() .unwrap(); - let def_id = tcx.hir().body_owner_def_id(body_id); + let def_id = tcx.hir_body_owner_def_id(body_id); let body_with_facts = borrowck_facts::get_body_with_borrowck_facts(tcx, def_id); debug!("{}", body_with_facts.body.to_string(tcx).unwrap()); @@ -181,6 +176,7 @@ impl<'tcx> CompileResult<'tcx> { } struct TestCallbacks { + input: String, callback: Option, } @@ -190,6 +186,7 @@ where { fn config(&mut self, config: &mut rustc_interface::Config) { config.override_queries = Some(borrowck_facts::override_queries); + config.file_loader = Some(Box::new(StringLoader(self.input.clone()))); } fn after_analysis( diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 64878662b..95c63d8bd 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-12-15" +channel = "nightly-2025-03-03" components = ["clippy", "rust-src", "rustc-dev", "llvm-tools-preview"]