From 592c8154de90b3ef2496a7f1581ca8711f670ac1 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Mon, 20 Apr 2026 08:59:25 +0300 Subject: [PATCH] Add `#[rust_analyzer::prefer_underscore_import]` to the traits in `rustc_type_ir::inherent` This is a new attribute that instructs rust-analyzer to prefer importing the trait `as _`. It is useful for these traits since their names often clashes with the type. --- compiler/rustc_type_ir/src/inherent.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index cf94dc4298958..a336313e90b8f 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -17,6 +17,7 @@ use crate::{ self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, UpcastFrom, }; +#[rust_analyzer::prefer_underscore_import] pub trait Ty>: Copy + Debug @@ -195,6 +196,7 @@ pub trait Ty>: } } +#[rust_analyzer::prefer_underscore_import] pub trait Tys>: Copy + Debug + Hash + Eq + SliceLike + TypeFoldable + Default { @@ -203,6 +205,7 @@ pub trait Tys>: fn output(self) -> I::Ty; } +#[rust_analyzer::prefer_underscore_import] pub trait FSigKind>: Copy + Debug + Hash + Eq { /// The identity function. fn fn_sig_kind(self) -> Self; @@ -220,6 +223,7 @@ pub trait FSigKind>: Copy + Debug + Hash + Eq { fn c_variadic(self) -> bool; } +#[rust_analyzer::prefer_underscore_import] pub trait Abi>: Copy + Debug + Hash + Eq { /// The identity function. fn abi(self) -> Self; @@ -237,6 +241,7 @@ pub trait Abi>: Copy + Debug + Hash + Eq { fn unpack_abi(abi_index: u8) -> Self; } +#[rust_analyzer::prefer_underscore_import] pub trait Safety>: Copy + Debug + Hash + Eq { /// The `safe` safety mode. fn safe() -> Self; @@ -251,6 +256,7 @@ pub trait Safety>: Copy + Debug + Hash + Eq { fn prefix_str(self) -> &'static str; } +#[rust_analyzer::prefer_underscore_import] pub trait Region>: Copy + Debug @@ -276,6 +282,7 @@ pub trait Region>: } } +#[rust_analyzer::prefer_underscore_import] pub trait Const>: Copy + Debug @@ -320,19 +327,23 @@ pub trait Const>: } } +#[rust_analyzer::prefer_underscore_import] pub trait ValueConst>: Copy + Debug + Hash + Eq { fn ty(self) -> I::Ty; fn valtree(self) -> I::ValTree; } +#[rust_analyzer::prefer_underscore_import] pub trait ExprConst>: Copy + Debug + Hash + Eq + Relate { fn args(self) -> I::GenericArgs; } +#[rust_analyzer::prefer_underscore_import] pub trait GenericsOf> { fn count(&self) -> usize; } +#[rust_analyzer::prefer_underscore_import] pub trait GenericArg>: Copy + Debug @@ -387,6 +398,7 @@ pub trait GenericArg>: } } +#[rust_analyzer::prefer_underscore_import] pub trait Term>: Copy + Debug + Hash + Eq + IntoKind> + TypeFoldable + Relate { @@ -434,6 +446,7 @@ pub trait Term>: } } +#[rust_analyzer::prefer_underscore_import] pub trait GenericArgs>: Copy + Debug + Hash + Eq + SliceLike + Default + Relate { @@ -473,6 +486,7 @@ pub trait GenericArgs>: } } +#[rust_analyzer::prefer_underscore_import] pub trait Predicate>: Copy + Debug @@ -528,6 +542,7 @@ pub trait Predicate>: } } +#[rust_analyzer::prefer_underscore_import] pub trait Clause>: Copy + Debug @@ -577,6 +592,7 @@ pub trait Clause>: fn instantiate_supertrait(self, cx: I, trait_ref: ty::Binder>) -> Self; } +#[rust_analyzer::prefer_underscore_import] pub trait Clauses>: Copy + Debug @@ -589,16 +605,19 @@ pub trait Clauses>: { } +#[rust_analyzer::prefer_underscore_import] pub trait IntoKind { type Kind; fn kind(self) -> Self::Kind; } +#[rust_analyzer::prefer_underscore_import] pub trait ParamLike: Copy + Debug + Hash + Eq { fn index(self) -> u32; } +#[rust_analyzer::prefer_underscore_import] pub trait AdtDef: Copy + Debug + Hash + Eq { fn def_id(self) -> I::AdtId; @@ -635,10 +654,12 @@ pub trait AdtDef: Copy + Debug + Hash + Eq { fn destructor(self, interner: I) -> Option; } +#[rust_analyzer::prefer_underscore_import] pub trait ParamEnv: Copy + Debug + Hash + Eq + TypeFoldable { fn caller_bounds(self) -> impl SliceLike; } +#[rust_analyzer::prefer_underscore_import] pub trait Features: Copy { fn generic_const_exprs(self) -> bool; @@ -647,6 +668,7 @@ pub trait Features: Copy { fn feature_bound_holds_in_crate(self, symbol: I::Symbol) -> bool; } +#[rust_analyzer::prefer_underscore_import] pub trait DefId: Copy + Debug + Hash + Eq + TypeFoldable { fn is_local(self) -> bool; @@ -663,6 +685,7 @@ impl + Into + TryFrom: Copy + Debug + Hash + Eq + Relate + SliceLike>> { @@ -677,10 +700,12 @@ pub trait BoundExistentialPredicates: ) -> impl IntoIterator>>; } +#[rust_analyzer::prefer_underscore_import] pub trait Span: Copy + Debug + Hash + Eq + TypeFoldable { fn dummy() -> Self; } +#[rust_analyzer::prefer_underscore_import] pub trait OpaqueTypeStorageEntries: Debug + Copy + Default { /// Whether the number of opaques has changed in a way that necessitates /// reevaluating a goal. For now, this is only when the number of non-duplicated @@ -767,6 +792,7 @@ impl<'a, S: SliceLike> SliceLike for &'a S { } } +#[rust_analyzer::prefer_underscore_import] pub trait Symbol: Copy + Hash + PartialEq + Eq + Debug { fn is_kw_underscore_lifetime(self) -> bool; }