diff --git a/compiler/rustc_borrowck/src/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs index d257145373f72..7080fc8e15a53 100644 --- a/compiler/rustc_borrowck/src/consumers.rs +++ b/compiler/rustc_borrowck/src/consumers.rs @@ -10,7 +10,7 @@ use rustc_middle::traits::DefiningAnchor; use rustc_middle::ty::TyCtxt; use std::rc::Rc; -use crate::borrow_set::BorrowSet; +use crate::{borrow_set::BorrowSet, BorrowCheckResult}; pub use super::{ constraints::OutlivesConstraint, @@ -107,9 +107,18 @@ pub fn get_body_with_borrowck_facts( def: LocalDefId, options: ConsumerOptions, ) -> BodyWithBorrowckFacts<'_> { + *do_mir_borrowck(tcx, def, options).1.unwrap() +} + +/// Like [`get_body_with_borrowck_facts`], but also return the borrow check results. +pub fn do_mir_borrowck<'tcx>( + tcx: TyCtxt<'tcx>, + def: LocalDefId, + options: ConsumerOptions, +) -> (BorrowCheckResult<'tcx>, Option>>) { let (input_body, promoted) = tcx.mir_promoted(def); let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def)).build(); let input_body: &Body<'_> = &input_body.borrow(); let promoted: &IndexSlice<_, _> = &promoted.borrow(); - *super::do_mir_borrowck(&infcx, input_body, promoted, Some(options)).1.unwrap() + super::do_mir_borrowck(&infcx, input_body, promoted, Some(options)) } diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 2a0cb49672b83..892f1ff01eb59 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1366,7 +1366,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Evaluate whether `sup_region: sub_region`. #[instrument(skip(self), level = "debug", ret)] - fn eval_outlives(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool { + pub fn eval_outlives(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool { debug!( "sup_region's value = {:?} universal={:?}", self.region_value_str(sup_region), diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 947530a1b65a9..251f836b77e3b 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -190,9 +190,9 @@ impl LintStore { pub fn register_late_pass( &mut self, pass: impl for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx> - + 'static - + sync::DynSend - + sync::DynSync, + + 'static + + sync::DynSend + + sync::DynSync, ) { self.late_passes.push(Box::new(pass)); } @@ -200,9 +200,9 @@ impl LintStore { pub fn register_late_mod_pass( &mut self, pass: impl for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx> - + 'static - + sync::DynSend - + sync::DynSync, + + 'static + + sync::DynSend + + sync::DynSync, ) { self.late_module_passes.push(Box::new(pass)); } @@ -533,6 +533,7 @@ impl LintStore { } /// Context for lint checking outside of type inference. +#[derive(Clone)] pub struct LateContext<'tcx> { /// Type context we're checking in. pub tcx: TyCtxt<'tcx>, @@ -1145,6 +1146,20 @@ impl LintContext for EarlyContext<'_> { } impl<'tcx> LateContext<'tcx> { + pub fn new(tcx: TyCtxt<'tcx>, enclosing_body: Option) -> Self { + Self { + tcx, + enclosing_body, + cached_typeck_results: Cell::new(None), + param_env: ty::ParamEnv::empty(), + effective_visibilities: &tcx.effective_visibilities(()), + lint_store: crate::unerased_lint_store(tcx), + last_node_with_lint_attrs: hir::CRATE_HIR_ID, + generics: None, + only_module: false, + } + } + /// Gets the type-checking results for the current body, /// or `None` if outside a body. pub fn maybe_typeck_results(&self) -> Option<&'tcx ty::TypeckResults<'tcx>> { diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 8a4a451f8a837..ffc22f733c343 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -43,8 +43,8 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({ /// Implements the AST traversal for late lint passes. `T` provides the /// `check_*` methods. pub struct LateContextAndPass<'tcx, T: LateLintPass<'tcx>> { - context: LateContext<'tcx>, - pass: T, + pub context: LateContext<'tcx>, + pub pass: T, } impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> { diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 5e3f057d42834..5fad041db6394 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -126,7 +126,7 @@ pub use builtin::SoftLints; pub use context::{CheckLintNameResult, FindLintError, LintStore}; pub use context::{EarlyContext, LateContext, LintContext}; pub use early::{check_ast_node, EarlyCheckNode}; -pub use late::{check_crate, unerased_lint_store}; +pub use late::{check_crate, unerased_lint_store, LateContextAndPass}; pub use passes::{EarlyLintPass, LateLintPass}; pub use rustc_session::lint::Level::{self, *}; pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Lint, LintId};