diff options
| author | Michael Goulet <michael@errs.io> | 2024-02-13 23:49:39 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-02-16 15:07:37 +0000 |
| commit | 9c25823bb4bba6416ca4b15cd956ae92716f82eb (patch) | |
| tree | f721cae71a460391c47a38917f4dd63574b0aee9 /compiler/rustc_borrowck/src | |
| parent | 3250e953050be1a6867aac3745742f86ab406361 (diff) | |
| download | rust-9c25823bb4bba6416ca4b15cd956ae92716f82eb.tar.gz rust-9c25823bb4bba6416ca4b15cd956ae92716f82eb.zip | |
Use extension trait derive
Diffstat (limited to 'compiler/rustc_borrowck/src')
| -rw-r--r-- | compiler/rustc_borrowck/src/facts.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_borrowck/src/place_ext.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_borrowck/src/region_infer/opaque_types.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_borrowck/src/universal_regions.rs | 22 |
4 files changed, 11 insertions, 52 deletions
diff --git a/compiler/rustc_borrowck/src/facts.rs b/compiler/rustc_borrowck/src/facts.rs index 68dc9a6764b..da14408fb69 100644 --- a/compiler/rustc_borrowck/src/facts.rs +++ b/compiler/rustc_borrowck/src/facts.rs @@ -2,6 +2,7 @@ use crate::location::{LocationIndex, LocationTable}; use crate::BorrowIndex; use polonius_engine::AllFacts as PoloniusFacts; use polonius_engine::Atom; +use rustc_macros::extension; use rustc_middle::mir::Local; use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_mir_dataflow::move_paths::MovePathIndex; @@ -24,20 +25,10 @@ impl polonius_engine::FactTypes for RustcFacts { pub type AllFacts = PoloniusFacts<RustcFacts>; -pub(crate) trait AllFactsExt { +#[extension] +pub(crate) impl AllFactsExt for AllFacts { /// Returns `true` if there is a need to gather `AllFacts` given the /// current `-Z` flags. - fn enabled(tcx: TyCtxt<'_>) -> bool; - - fn write_to_dir( - &self, - dir: impl AsRef<Path>, - location_table: &LocationTable, - ) -> Result<(), Box<dyn Error>>; -} - -impl AllFactsExt for AllFacts { - /// Return fn enabled(tcx: TyCtxt<'_>) -> bool { tcx.sess.opts.unstable_opts.nll_facts || tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled() diff --git a/compiler/rustc_borrowck/src/place_ext.rs b/compiler/rustc_borrowck/src/place_ext.rs index b59ab7fafa5..ac8991ccf00 100644 --- a/compiler/rustc_borrowck/src/place_ext.rs +++ b/compiler/rustc_borrowck/src/place_ext.rs @@ -1,11 +1,12 @@ use crate::borrow_set::LocalsStateAtExit; use rustc_hir as hir; +use rustc_macros::extension; use rustc_middle::mir::ProjectionElem; use rustc_middle::mir::{Body, Mutability, Place}; use rustc_middle::ty::{self, TyCtxt}; -/// Extension methods for the `Place` type. -pub trait PlaceExt<'tcx> { +#[extension] +pub impl<'tcx> PlaceExt<'tcx> for Place<'tcx> { /// Returns `true` if we can safely ignore borrows of this place. /// This is true whenever there is no action that the user can do /// to the place `self` that would invalidate the borrow. This is true @@ -15,15 +16,6 @@ pub trait PlaceExt<'tcx> { tcx: TyCtxt<'tcx>, body: &Body<'tcx>, locals_state_at_exit: &LocalsStateAtExit, - ) -> bool; -} - -impl<'tcx> PlaceExt<'tcx> for Place<'tcx> { - fn ignore_borrow( - &self, - tcx: TyCtxt<'tcx>, - body: &Body<'tcx>, - locals_state_at_exit: &LocalsStateAtExit, ) -> bool { // If a local variable is immutable, then we only need to track borrows to guard // against two kinds of errors: diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index cd2fe56ca49..4aac392ef39 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -6,6 +6,7 @@ use rustc_hir::OpaqueTyOrigin; use rustc_infer::infer::InferCtxt; use rustc_infer::infer::TyCtxtInferExt as _; use rustc_infer::traits::{Obligation, ObligationCause}; +use rustc_macros::extension; use rustc_middle::traits::DefiningAnchor; use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable}; @@ -225,15 +226,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { } } -pub trait InferCtxtExt<'tcx> { - fn infer_opaque_definition_from_instantiation( - &self, - opaque_type_key: OpaqueTypeKey<'tcx>, - instantiated_ty: OpaqueHiddenType<'tcx>, - ) -> Ty<'tcx>; -} - -impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { +#[extension] +pub impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { /// Given the fully resolved, instantiated type for an opaque /// type, i.e., the value of an inference variable like C1 or C2 /// (*), computes the "definition type" for an opaque type diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 90e8f1b93b2..f9a8543e28d 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -22,6 +22,7 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::BodyOwnerKind; use rustc_index::IndexVec; use rustc_infer::infer::NllRegionVariableOrigin; +use rustc_macros::extension; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt}; @@ -793,26 +794,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { } } -trait InferCtxtExt<'tcx> { - fn replace_free_regions_with_nll_infer_vars<T>( - &self, - origin: NllRegionVariableOrigin, - value: T, - ) -> T - where - T: TypeFoldable<TyCtxt<'tcx>>; - - fn replace_bound_regions_with_nll_infer_vars<T>( - &self, - origin: NllRegionVariableOrigin, - all_outlive_scope: LocalDefId, - value: ty::Binder<'tcx, T>, - indices: &mut UniversalRegionIndices<'tcx>, - ) -> T - where - T: TypeFoldable<TyCtxt<'tcx>>; -} - +#[extension] impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> { #[instrument(skip(self), level = "debug")] fn replace_free_regions_with_nll_infer_vars<T>( |
