Skip to content

Commit 28e3ea5

Browse files
committed
Auto merge of #153026 - JonathanBrouwer:rollup-PAPpAYW, r=JonathanBrouwer
Rollup of 14 pull requests Successful merges: - rust-lang/rust#153007 (`rust-analyzer` subtree update) - rust-lang/rust#152670 (Simplify ThinLTO handling) - rust-lang/rust#152768 (Enable autodiff in ci for all major os) - rust-lang/rust#152908 (Enable rust.remap-debuginfo in the dist profile) - rust-lang/rust#152999 (Check importing `crate`/`$crate`/`super` after handling `self`) - rust-lang/rust#152003 (Reflection TypeId::trait_info_of) - rust-lang/rust#152976 (Revert relative paths for std links in rustc-docs) - rust-lang/rust#152985 (Port `#[feature]` to the new attribute system) - rust-lang/rust#152989 (Port `#[rustc_inherit_overflow_checks]` to the new attribute parsers) - rust-lang/rust#152991 (fix interpreter tracing output) - rust-lang/rust#153004 (Superficial tweaks to the query modifier docs in `rustc_middle::query::modifiers`) - rust-lang/rust#153008 (bootstrap.compiler.toml: update name of primary branch) - rust-lang/rust#153016 (Migration of `LintDiagnostic` - part 2) - rust-lang/rust#153020 (rustdoc: Improve sentence for documented empty impl blocks) Failed merges: - rust-lang/rust#152988 (Port `#[register_tool]` to the new attribute system)
2 parents 61e7ff7 + 8734618 commit 28e3ea5

55 files changed

Lines changed: 2058 additions & 837 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
ref: ${{ github.event.pull_request.head.sha }}
5151

5252
- name: Install rustup-toolchain-install-master
53-
run: cargo install rustup-toolchain-install-master@1.6.0
53+
run: cargo install rustup-toolchain-install-master@1.11.0
5454

5555
# Install a pinned rustc commit to avoid surprises
5656
- name: Install Rust toolchain
@@ -226,7 +226,12 @@ jobs:
226226

227227
strategy:
228228
matrix:
229-
target: [powerpc-unknown-linux-gnu, x86_64-unknown-linux-musl, wasm32-unknown-unknown]
229+
target:
230+
[
231+
powerpc-unknown-linux-gnu,
232+
x86_64-unknown-linux-musl,
233+
wasm32-unknown-unknown,
234+
]
230235
include:
231236
# The rust-analyzer binary is not expected to compile on WASM, but the IDE
232237
# crate should
@@ -330,7 +335,18 @@ jobs:
330335
run: typos
331336

332337
conclusion:
333-
needs: [rust, rust-cross, typescript, typo-check, proc-macro-srv, miri, rustfmt, clippy, analysis-stats]
338+
needs:
339+
[
340+
rust,
341+
rust-cross,
342+
typescript,
343+
typo-check,
344+
proc-macro-srv,
345+
miri,
346+
rustfmt,
347+
clippy,
348+
analysis-stats,
349+
]
334350
# We need to ensure this job does *not* get skipped if its dependencies fail,
335351
# because a skipped job is considered a success by GitHub. So we have to
336352
# overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run

crates/hir-def/src/hir/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static EMPTY: LazyLock<Arc<GenericParams>> = LazyLock::new(|| {
184184

185185
impl GenericParams {
186186
/// The index of the self param in the generic of the non-parent definition.
187-
pub(crate) const SELF_PARAM_ID_IN_SELF: la_arena::Idx<TypeOrConstParamData> =
187+
pub const SELF_PARAM_ID_IN_SELF: la_arena::Idx<TypeOrConstParamData> =
188188
LocalTypeOrConstParamId::from_raw(RawIdx::from_u32(0));
189189

190190
pub fn new(db: &dyn DefDatabase, def: GenericDefId) -> Arc<GenericParams> {

crates/hir-def/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ use crate::{
8686
builtin_type::BuiltinType,
8787
db::DefDatabase,
8888
expr_store::ExpressionStoreSourceMap,
89-
hir::generics::{LocalLifetimeParamId, LocalTypeOrConstParamId},
89+
hir::generics::{GenericParams, LocalLifetimeParamId, LocalTypeOrConstParamId},
9090
nameres::{
9191
LocalDefMap,
9292
assoc::{ImplItems, TraitItems},
@@ -553,15 +553,25 @@ pub struct TypeOrConstParamId {
553553
pub struct TypeParamId(TypeOrConstParamId);
554554

555555
impl TypeParamId {
556+
#[inline]
556557
pub fn parent(&self) -> GenericDefId {
557558
self.0.parent
558559
}
560+
561+
#[inline]
559562
pub fn local_id(&self) -> LocalTypeOrConstParamId {
560563
self.0.local_id
561564
}
562-
}
563565

564-
impl TypeParamId {
566+
#[inline]
567+
pub fn trait_self(trait_: TraitId) -> TypeParamId {
568+
TypeParamId::from_unchecked(TypeOrConstParamId {
569+
parent: trait_.into(),
570+
local_id: GenericParams::SELF_PARAM_ID_IN_SELF,
571+
})
572+
}
573+
574+
#[inline]
565575
/// Caller should check if this toc id really belongs to a type
566576
pub fn from_unchecked(it: TypeOrConstParamId) -> Self {
567577
Self(it)

crates/hir-ty/src/builtin_derive.rs

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ fn coerce_pointee_new_type_param(trait_id: TraitId) -> TypeParamId {
3535
})
3636
}
3737

38+
fn trait_args(trait_: BuiltinDeriveImplTrait, self_ty: Ty<'_>) -> GenericArgs<'_> {
39+
match trait_ {
40+
BuiltinDeriveImplTrait::Copy
41+
| BuiltinDeriveImplTrait::Clone
42+
| BuiltinDeriveImplTrait::Default
43+
| BuiltinDeriveImplTrait::Debug
44+
| BuiltinDeriveImplTrait::Hash
45+
| BuiltinDeriveImplTrait::Eq
46+
| BuiltinDeriveImplTrait::Ord => GenericArgs::new_from_slice(&[self_ty.into()]),
47+
BuiltinDeriveImplTrait::PartialOrd | BuiltinDeriveImplTrait::PartialEq => {
48+
GenericArgs::new_from_slice(&[self_ty.into(), self_ty.into()])
49+
}
50+
BuiltinDeriveImplTrait::CoerceUnsized | BuiltinDeriveImplTrait::DispatchFromDyn => {
51+
panic!("`CoerceUnsized` and `DispatchFromDyn` have special generics")
52+
}
53+
}
54+
}
55+
3856
pub(crate) fn generics_of<'db>(interner: DbInterner<'db>, id: BuiltinDeriveImplId) -> Generics {
3957
let db = interner.db;
4058
let loc = id.loc(db);
@@ -95,21 +113,19 @@ pub fn impl_trait<'db>(
95113
| BuiltinDeriveImplTrait::Debug
96114
| BuiltinDeriveImplTrait::Hash
97115
| BuiltinDeriveImplTrait::Ord
98-
| BuiltinDeriveImplTrait::Eq => {
116+
| BuiltinDeriveImplTrait::Eq
117+
| BuiltinDeriveImplTrait::PartialOrd
118+
| BuiltinDeriveImplTrait::PartialEq => {
99119
let self_ty = Ty::new_adt(
100120
interner,
101121
loc.adt,
102122
GenericArgs::identity_for_item(interner, loc.adt.into()),
103123
);
104-
EarlyBinder::bind(TraitRef::new(interner, trait_id.into(), [self_ty]))
105-
}
106-
BuiltinDeriveImplTrait::PartialOrd | BuiltinDeriveImplTrait::PartialEq => {
107-
let self_ty = Ty::new_adt(
124+
EarlyBinder::bind(TraitRef::new_from_args(
108125
interner,
109-
loc.adt,
110-
GenericArgs::identity_for_item(interner, loc.adt.into()),
111-
);
112-
EarlyBinder::bind(TraitRef::new(interner, trait_id.into(), [self_ty, self_ty]))
126+
trait_id.into(),
127+
trait_args(loc.trait_, self_ty),
128+
))
113129
}
114130
BuiltinDeriveImplTrait::CoerceUnsized | BuiltinDeriveImplTrait::DispatchFromDyn => {
115131
let generic_params = GenericParams::new(db, loc.adt.into());
@@ -260,7 +276,8 @@ fn simple_trait_predicates<'db>(
260276
let param_idx =
261277
param_idx.into_raw().into_u32() + (generic_params.len_lifetimes() as u32);
262278
let param_ty = Ty::new_param(interner, param_id, param_idx);
263-
let trait_ref = TraitRef::new(interner, trait_id.into(), [param_ty]);
279+
let trait_args = trait_args(loc.trait_, param_ty);
280+
let trait_ref = TraitRef::new_from_args(interner, trait_id.into(), trait_args);
264281
trait_ref.upcast(interner)
265282
});
266283
let mut assoc_type_bounds = Vec::new();
@@ -270,12 +287,14 @@ fn simple_trait_predicates<'db>(
270287
&mut assoc_type_bounds,
271288
interner.db.field_types(id.into()),
272289
trait_id,
290+
loc.trait_,
273291
),
274292
AdtId::UnionId(id) => extend_assoc_type_bounds(
275293
interner,
276294
&mut assoc_type_bounds,
277295
interner.db.field_types(id.into()),
278296
trait_id,
297+
loc.trait_,
279298
),
280299
AdtId::EnumId(id) => {
281300
for &(variant_id, _, _) in &id.enum_variants(interner.db).variants {
@@ -284,6 +303,7 @@ fn simple_trait_predicates<'db>(
284303
&mut assoc_type_bounds,
285304
interner.db.field_types(variant_id.into()),
286305
trait_id,
306+
loc.trait_,
287307
)
288308
}
289309
}
@@ -305,12 +325,14 @@ fn extend_assoc_type_bounds<'db>(
305325
interner: DbInterner<'db>,
306326
assoc_type_bounds: &mut Vec<Clause<'db>>,
307327
fields: &ArenaMap<LocalFieldId, StoredEarlyBinder<StoredTy>>,
308-
trait_: TraitId,
328+
trait_id: TraitId,
329+
trait_: BuiltinDeriveImplTrait,
309330
) {
310331
struct ProjectionFinder<'a, 'db> {
311332
interner: DbInterner<'db>,
312333
assoc_type_bounds: &'a mut Vec<Clause<'db>>,
313-
trait_: TraitId,
334+
trait_id: TraitId,
335+
trait_: BuiltinDeriveImplTrait,
314336
}
315337

316338
impl<'db> TypeVisitor<DbInterner<'db>> for ProjectionFinder<'_, 'db> {
@@ -319,15 +341,20 @@ fn extend_assoc_type_bounds<'db>(
319341
fn visit_ty(&mut self, t: Ty<'db>) -> Self::Result {
320342
if let TyKind::Alias(AliasTyKind::Projection, _) = t.kind() {
321343
self.assoc_type_bounds.push(
322-
TraitRef::new(self.interner, self.trait_.into(), [t]).upcast(self.interner),
344+
TraitRef::new_from_args(
345+
self.interner,
346+
self.trait_id.into(),
347+
trait_args(self.trait_, t),
348+
)
349+
.upcast(self.interner),
323350
);
324351
}
325352

326353
t.super_visit_with(self)
327354
}
328355
}
329356

330-
let mut visitor = ProjectionFinder { interner, assoc_type_bounds, trait_ };
357+
let mut visitor = ProjectionFinder { interner, assoc_type_bounds, trait_id, trait_ };
331358
for (_, field) in fields.iter() {
332359
field.get().instantiate_identity().visit_with(&mut visitor);
333360
}
@@ -488,10 +515,12 @@ struct MultiGenericParams<'a, T, #[pointee] U: ?Sized, const N: usize>(*const U)
488515
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
489516
struct Simple;
490517
491-
trait Trait {}
518+
trait Trait {
519+
type Assoc;
520+
}
492521
493522
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
494-
struct WithGenerics<'a, T: Trait, const N: usize>(&'a [T; N]);
523+
struct WithGenerics<'a, T: Trait, const N: usize>(&'a [T; N], T::Assoc);
495524
"#,
496525
expect![[r#"
497526
@@ -514,41 +543,49 @@ struct WithGenerics<'a, T: Trait, const N: usize>(&'a [T; N]);
514543
Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
515544
Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
516545
Clause(Binder { value: TraitPredicate(#1: Debug, polarity:Positive), bound_vars: [] })
546+
Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Debug, polarity:Positive), bound_vars: [] })
517547
518548
Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
519549
Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
520550
Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
521551
Clause(Binder { value: TraitPredicate(#1: Clone, polarity:Positive), bound_vars: [] })
552+
Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Clone, polarity:Positive), bound_vars: [] })
522553
523554
Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
524555
Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
525556
Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
526557
Clause(Binder { value: TraitPredicate(#1: Copy, polarity:Positive), bound_vars: [] })
558+
Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Copy, polarity:Positive), bound_vars: [] })
527559
528560
Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
529561
Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
530562
Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
531-
Clause(Binder { value: TraitPredicate(#1: PartialEq, polarity:Positive), bound_vars: [] })
563+
Clause(Binder { value: TraitPredicate(#1: PartialEq<[#1]>, polarity:Positive), bound_vars: [] })
564+
Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): PartialEq<[Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. })]>, polarity:Positive), bound_vars: [] })
532565
533566
Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
534567
Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
535568
Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
536569
Clause(Binder { value: TraitPredicate(#1: Eq, polarity:Positive), bound_vars: [] })
570+
Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Eq, polarity:Positive), bound_vars: [] })
537571
538572
Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
539573
Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
540574
Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
541-
Clause(Binder { value: TraitPredicate(#1: PartialOrd, polarity:Positive), bound_vars: [] })
575+
Clause(Binder { value: TraitPredicate(#1: PartialOrd<[#1]>, polarity:Positive), bound_vars: [] })
576+
Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): PartialOrd<[Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. })]>, polarity:Positive), bound_vars: [] })
542577
543578
Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
544579
Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
545580
Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
546581
Clause(Binder { value: TraitPredicate(#1: Ord, polarity:Positive), bound_vars: [] })
582+
Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Ord, polarity:Positive), bound_vars: [] })
547583
548584
Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
549585
Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
550586
Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
551587
Clause(Binder { value: TraitPredicate(#1: Hash, polarity:Positive), bound_vars: [] })
588+
Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Hash, polarity:Positive), bound_vars: [] })
552589
553590
"#]],
554591
);

crates/hir-ty/src/generics.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,6 @@ impl Generics {
224224
}
225225
}
226226

227-
pub(crate) fn trait_self_param_idx(db: &dyn DefDatabase, def: GenericDefId) -> Option<usize> {
228-
match def {
229-
GenericDefId::TraitId(_) => {
230-
let params = db.generic_params(def);
231-
params.trait_self_param().map(|idx| idx.into_raw().into_u32() as usize)
232-
}
233-
GenericDefId::ImplId(_) => None,
234-
_ => {
235-
let parent_def = parent_generic_def(db, def)?;
236-
let parent_params = db.generic_params(parent_def);
237-
let parent_self_idx = parent_params.trait_self_param()?.into_raw().into_u32() as usize;
238-
Some(parent_self_idx)
239-
}
240-
}
241-
}
242-
243227
pub(crate) fn parent_generic_def(db: &dyn DefDatabase, def: GenericDefId) -> Option<GenericDefId> {
244228
let container = match def {
245229
GenericDefId::FunctionId(it) => it.lookup(db).container,

0 commit comments

Comments
 (0)