Skip to content

Commit a9dbf63

Browse files
Move trait into attr so it's greppable
1 parent 9c25823 commit a9dbf63

File tree

31 files changed

+91
-80
lines changed

31 files changed

+91
-80
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
191191
}
192192
}
193193

194-
#[extension]
195-
impl ResolverAstLoweringExt for ResolverAstLowering {
194+
#[extension(trait ResolverAstLoweringExt)]
195+
impl ResolverAstLowering {
196196
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>> {
197197
if let ExprKind::Path(None, path) = &expr.kind {
198198
// Don't perform legacy const generics rewriting if the path already

compiler/rustc_borrowck/src/facts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ impl polonius_engine::FactTypes for RustcFacts {
2525

2626
pub type AllFacts = PoloniusFacts<RustcFacts>;
2727

28-
#[extension]
29-
pub(crate) impl AllFactsExt for AllFacts {
28+
#[extension(pub(crate) trait AllFactsExt)]
29+
impl AllFacts {
3030
/// Returns `true` if there is a need to gather `AllFacts` given the
3131
/// current `-Z` flags.
3232
fn enabled(tcx: TyCtxt<'_>) -> bool {

compiler/rustc_borrowck/src/place_ext.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use rustc_middle::mir::ProjectionElem;
55
use rustc_middle::mir::{Body, Mutability, Place};
66
use rustc_middle::ty::{self, TyCtxt};
77

8-
#[extension]
9-
pub impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
8+
#[extension(pub trait PlaceExt<'tcx>)]
9+
impl<'tcx> Place<'tcx> {
1010
/// Returns `true` if we can safely ignore borrows of this place.
1111
/// This is true whenever there is no action that the user can do
1212
/// to the place `self` that would invalidate the borrow. This is true

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
226226
}
227227
}
228228

229-
#[extension]
230-
pub impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
229+
#[extension(pub trait InferCtxtExt<'tcx>)]
230+
impl<'tcx> InferCtxt<'tcx> {
231231
/// Given the fully resolved, instantiated type for an opaque
232232
/// type, i.e., the value of an inference variable like C1 or C2
233233
/// (*), computes the "definition type" for an opaque type

compiler/rustc_borrowck/src/universal_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
794794
}
795795
}
796796

797-
#[extension]
798-
impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
797+
#[extension(trait InferCtxtExt<'tcx>)]
798+
impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
799799
#[instrument(skip(self), level = "debug")]
800800
fn replace_free_regions_with_nll_infer_vars<T>(
801801
&self,

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use std::fmt;
2828

2929
use crate::errors;
3030

31-
#[extension]
32-
impl RegionExt for ResolvedArg {
31+
#[extension(trait RegionExt)]
32+
impl ResolvedArg {
3333
fn early(param: &GenericParam<'_>) -> (LocalDefId, ResolvedArg) {
3434
debug!("ResolvedArg::early: def_id={:?}", param.def_id);
3535
(param.def_id, ResolvedArg::EarlyBound(param.def_id.to_def_id()))

compiler/rustc_infer/src/infer/canonical/instantiate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use rustc_middle::ty::{self, TyCtxt};
1313

1414
/// FIXME(-Znext-solver): This or public because it is shared with the
1515
/// new trait solver implementation. We should deduplicate canonicalization.
16-
#[extension]
17-
pub impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
16+
#[extension(pub trait CanonicalExt<'tcx, V>)]
17+
impl<'tcx, V> Canonical<'tcx, V> {
1818
/// Instantiate the wrapped value, replacing each canonical value
1919
/// with the value given in `var_values`.
2020
fn instantiate(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2786,8 +2786,8 @@ pub enum FailureCode {
27862786
Error0644,
27872787
}
27882788

2789-
#[extension]
2790-
pub impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
2789+
#[extension(pub trait ObligationCauseExt<'tcx>)]
2790+
impl<'tcx> ObligationCause<'tcx> {
27912791
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode {
27922792
use self::FailureCode::*;
27932793
use crate::traits::ObligationCauseCode::*;

compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ pub struct InferCtxtBuilder<'tcx> {
626626
next_trait_solver: bool,
627627
}
628628

629-
#[extension]
630-
pub impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
629+
#[extension(pub trait TyCtxtInferExt<'tcx>)]
630+
impl<'tcx> TyCtxt<'tcx> {
631631
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
632632
InferCtxtBuilder {
633633
tcx: self,

compiler/rustc_infer/src/traits/engine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub trait TraitEngine<'tcx>: 'tcx {
5252
) -> Vec<PredicateObligation<'tcx>>;
5353
}
5454

55-
#[extension]
56-
pub impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
55+
#[extension(pub trait TraitEngineExt<'tcx>)]
56+
impl<'tcx, T: ?Sized + TraitEngine<'tcx>> T {
5757
fn register_predicate_obligations(
5858
&mut self,
5959
infcx: &InferCtxt<'tcx>,

compiler/rustc_macros/src/extension.rs

+23-12
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ use syn::{
88
Token, TraitItem, TraitItemConst, TraitItemFn, TraitItemMacro, TraitItemType, Type, Visibility,
99
};
1010

11-
pub(crate) fn extension(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
12-
// Parse the input tokens into a syntax tree
13-
let Extension { attrs, generics, vis, trait_, self_ty, items } =
14-
parse_macro_input!(input as Extension);
11+
pub(crate) fn extension(
12+
attr: proc_macro::TokenStream,
13+
input: proc_macro::TokenStream,
14+
) -> proc_macro::TokenStream {
15+
let ExtensionAttr { vis, trait_ } = parse_macro_input!(attr as ExtensionAttr);
16+
let Impl { attrs, generics, self_ty, items } = parse_macro_input!(input as Impl);
1517
let headers: Vec<_> = items
1618
.iter()
1719
.map(|item| match item {
@@ -105,23 +107,32 @@ fn scrub_header(mut sig: Signature) -> Signature {
105107
sig
106108
}
107109

108-
struct Extension {
109-
attrs: Vec<Attribute>,
110+
struct ExtensionAttr {
110111
vis: Visibility,
111-
generics: Generics,
112112
trait_: Path,
113+
}
114+
115+
impl Parse for ExtensionAttr {
116+
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
117+
let vis = input.parse()?;
118+
let _: Token![trait] = input.parse()?;
119+
let trait_ = input.parse()?;
120+
Ok(ExtensionAttr { vis, trait_ })
121+
}
122+
}
123+
124+
struct Impl {
125+
attrs: Vec<Attribute>,
126+
generics: Generics,
113127
self_ty: Type,
114128
items: Vec<ImplItem>,
115129
}
116130

117-
impl Parse for Extension {
131+
impl Parse for Impl {
118132
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
119133
let attrs = input.call(Attribute::parse_outer)?;
120-
let vis = input.parse()?;
121134
let _: Token![impl] = input.parse()?;
122135
let generics = input.parse()?;
123-
let trait_ = input.parse()?;
124-
let _: Token![for] = input.parse()?;
125136
let self_ty = input.parse()?;
126137

127138
let content;
@@ -131,6 +142,6 @@ impl Parse for Extension {
131142
items.push(content.parse()?);
132143
}
133144

134-
Ok(Extension { attrs, generics, vis, trait_, self_ty, items })
145+
Ok(Impl { attrs, generics, self_ty, items })
135146
}
136147
}

compiler/rustc_macros/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub fn symbols(input: TokenStream) -> TokenStream {
4242
}
4343

4444
#[proc_macro_attribute]
45-
pub fn extension(_attr: TokenStream, input: TokenStream) -> TokenStream {
46-
extension::extension(input)
45+
pub fn extension(attr: TokenStream, input: TokenStream) -> TokenStream {
46+
extension::extension(attr, input)
4747
}
4848

4949
decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);

compiler/rustc_middle/src/ty/layout.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use std::fmt;
2323
use std::num::NonZero;
2424
use std::ops::Bound;
2525

26-
#[extension]
27-
pub impl IntegerExt for Integer {
26+
#[extension(pub trait IntegerExt)]
27+
impl Integer {
2828
#[inline]
2929
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>, signed: bool) -> Ty<'tcx> {
3030
match (*self, signed) {
@@ -111,8 +111,8 @@ pub impl IntegerExt for Integer {
111111
}
112112
}
113113

114-
#[extension]
115-
pub impl PrimitiveExt for Primitive {
114+
#[extension(pub trait PrimitiveExt)]
115+
impl Primitive {
116116
#[inline]
117117
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
118118
match *self {

compiler/rustc_middle/src/ty/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ impl<'tcx> Discr<'tcx> {
9696
}
9797
}
9898

99-
#[extension]
100-
pub impl IntTypeExt for IntegerType {
99+
#[extension(pub trait IntTypeExt)]
100+
impl IntegerType {
101101
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
102102
match self {
103103
IntegerType::Pointer(true) => tcx.types.isize,

compiler/rustc_trait_selection/src/infer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use std::fmt::Debug;
1717

1818
pub use rustc_infer::infer::*;
1919

20-
#[extension]
21-
pub impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
20+
#[extension(pub trait InferCtxtExt<'tcx>)]
21+
impl<'tcx> InferCtxt<'tcx> {
2222
fn type_is_copy_modulo_regions(&self, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
2323
let ty = self.resolve_vars_if_possible(ty);
2424

@@ -105,8 +105,8 @@ pub impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
105105
}
106106
}
107107

108-
#[extension]
109-
pub impl<'tcx> InferCtxtBuilderExt<'tcx> for InferCtxtBuilder<'tcx> {
108+
#[extension(pub trait InferCtxtBuilderExt<'tcx>)]
109+
impl<'tcx> InferCtxtBuilder<'tcx> {
110110
/// The "main method" for a canonicalized trait query. Given the
111111
/// canonical key `canonical_key`, this method will create a new
112112
/// inference context, instantiate the key, and run your operation

compiler/rustc_trait_selection/src/regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use rustc_infer::infer::{InferCtxt, RegionResolutionError};
33
use rustc_middle::traits::query::NoSolution;
44
use rustc_middle::traits::ObligationCause;
55

6-
#[extension]
7-
pub impl<'tcx> InferCtxtRegionExt<'tcx> for InferCtxt<'tcx> {
6+
#[extension(pub trait InferCtxtRegionExt<'tcx>)]
7+
impl<'tcx> InferCtxt<'tcx> {
88
/// Resolve regions, using the deep normalizer to normalize any type-outlives
99
/// obligations in the process. This is in `rustc_trait_selection` because
1010
/// we need to normalize.

compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ pub enum GenerateProofTree {
131131
Never,
132132
}
133133

134-
#[extension]
135-
pub impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx> {
134+
#[extension(pub trait InferCtxtEvalExt<'tcx>)]
135+
impl<'tcx> InferCtxt<'tcx> {
136136
/// Evaluates a goal from **outside** of the trait solver.
137137
///
138138
/// Using this while inside of the solver is wrong as it uses a new

compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::solve::inspect::ProofTreeBuilder;
1717
use crate::traits::StructurallyNormalizeExt;
1818
use crate::traits::TraitEngineExt;
1919

20-
#[extension]
21-
pub impl<'tcx> InferCtxtSelectExt<'tcx> for InferCtxt<'tcx> {
20+
#[extension(pub trait InferCtxtSelectExt<'tcx>)]
21+
impl<'tcx> InferCtxt<'tcx> {
2222
fn select_in_new_trait_solver(
2323
&self,
2424
obligation: &PolyTraitObligation<'tcx>,

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ pub trait ProofTreeVisitor<'tcx> {
216216
fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) -> ControlFlow<Self::BreakTy>;
217217
}
218218

219-
#[extension]
220-
pub impl<'tcx> ProofTreeInferCtxtExt<'tcx> for InferCtxt<'tcx> {
219+
#[extension(pub trait ProofTreeInferCtxtExt<'tcx>)]
220+
impl<'tcx> InferCtxt<'tcx> {
221221
fn visit_proof_tree<V: ProofTreeVisitor<'tcx>>(
222222
&self,
223223
goal: Goal<'tcx, ty::Predicate<'tcx>>,

compiler/rustc_trait_selection/src/solve/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ enum GoalEvaluationKind {
6161
Nested { is_normalizes_to_hack: IsNormalizesToHack },
6262
}
6363

64-
#[extension]
65-
impl<'tcx> CanonicalResponseExt for Canonical<'tcx, Response<'tcx>> {
64+
#[extension(trait CanonicalResponseExt)]
65+
impl<'tcx> Canonical<'tcx, Response<'tcx>> {
6666
fn has_no_inference_or_external_constraints(&self) -> bool {
6767
self.value.external_constraints.region_constraints.is_empty()
6868
&& self.value.var_values.is_identity()

compiler/rustc_trait_selection/src/traits/engine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use rustc_middle::ty::TypeFoldable;
2727
use rustc_middle::ty::Variance;
2828
use rustc_middle::ty::{self, Ty, TyCtxt};
2929

30-
#[extension]
31-
pub impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> {
30+
#[extension(pub trait TraitEngineExt<'tcx>)]
31+
impl<'tcx> dyn TraitEngine<'tcx> {
3232
fn new(infcx: &InferCtxt<'tcx>) -> Box<Self> {
3333
if infcx.next_trait_solver() {
3434
Box::new(NextFulfillmentCtxt::new(infcx))

compiler/rustc_trait_selection/src/traits/error_reporting/infer_ctxt_ext.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use super::ArgKind;
1111

1212
pub use rustc_infer::traits::error_reporting::*;
1313

14-
#[extension]
15-
pub impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
14+
#[extension(pub trait InferCtxtExt<'tcx>)]
15+
impl<'tcx> InferCtxt<'tcx> {
1616
/// Given some node representing a fn-like thing in the HIR map,
1717
/// returns a span and `ArgKind` information that describes the
1818
/// arguments it expects. This can be supplied to

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ static ALLOWED_FORMAT_SYMBOLS: &[Symbol] = &[
3838
sym::Trait,
3939
];
4040

41-
#[extension]
42-
pub impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
41+
#[extension(pub trait TypeErrCtxtExt<'tcx>)]
42+
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
4343
fn impl_similar_to(
4444
&self,
4545
trait_ref: ty::PolyTraitRef<'tcx>,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ pub fn suggest_restriction<'tcx>(
236236
}
237237
}
238238

239-
#[extension]
240-
pub impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
239+
#[extension(pub trait TypeErrCtxtExt<'tcx>)]
240+
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
241241
fn suggest_restricting_param_bound(
242242
&self,
243243
err: &mut Diagnostic,

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ use super::{
5757

5858
pub use rustc_infer::traits::error_reporting::*;
5959

60-
#[extension]
61-
pub impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
60+
#[extension(pub trait TypeErrCtxtExt<'tcx>)]
61+
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
6262
fn report_fulfillment_errors(
6363
&self,
6464
mut errors: Vec<FulfillmentError<'tcx>>,
@@ -1326,8 +1326,8 @@ pub impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
13261326
}
13271327
}
13281328

1329-
#[extension]
1330-
pub(super) impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1329+
#[extension(pub(super) trait InferCtxtPrivExt<'tcx>)]
1330+
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
13311331
// returns if `cond` not occurring implies that `error` does not occur - i.e., that
13321332
// `error` occurring implies that `cond` occurs.
13331333
fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) -> bool {

compiler/rustc_trait_selection/src/traits/outlives_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ fn implied_outlives_bounds<'a, 'tcx>(
111111
bounds
112112
}
113113

114-
#[extension]
115-
pub impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
114+
#[extension(pub trait InferCtxtExt<'a, 'tcx>)]
115+
impl<'a, 'tcx: 'a> InferCtxt<'tcx> {
116116
/// Do *NOT* call this directly.
117117
fn implied_bounds_tys_compat(
118118
&'a self,

compiler/rustc_trait_selection/src/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub type ProjectionTyObligation<'tcx> = Obligation<'tcx, ty::AliasTy<'tcx>>;
5252

5353
pub(super) struct InProgress;
5454

55-
#[extension]
56-
pub impl<'tcx> NormalizeExt<'tcx> for At<'_, 'tcx> {
55+
#[extension(pub trait NormalizeExt<'tcx>)]
56+
impl<'tcx> At<'_, 'tcx> {
5757
/// Normalize a value using the `AssocTypeNormalizer`.
5858
///
5959
/// This normalization should be used when the type contains inference variables or the

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::infer::canonical::OriginalQueryValues;
44
use crate::infer::InferCtxt;
55
use crate::traits::{EvaluationResult, OverflowError, PredicateObligation, SelectionContext};
66

7-
#[extension]
8-
pub impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
7+
#[extension(pub trait InferCtxtExt<'tcx>)]
8+
impl<'tcx> InferCtxt<'tcx> {
99
/// Evaluates whether the predicate can be satisfied (by any means)
1010
/// in the given `ParamEnv`.
1111
fn predicate_may_hold(&self, obligation: &PredicateObligation<'tcx>) -> bool {

0 commit comments

Comments
 (0)