Skip to content

Commit d2823a1

Browse files
authored
Rollup merge of #111695 - fmease:dont-lump-together-alias-tys, r=compiler-errors
Exclude inherent projections from some alias type `match`es Updating (hopefully) all remaining `match`es which I overlooked to update when adding `AliasKind::Inherent` in #109410. Fixes #111399. Sadly the regression test is a clippy test instead of a rustc one as I don't know of another way to test that a trait bound like `Ty::InhProj: Trait` doesn't cause a crash without reaching a cycle error first (this is getting old ^^'). `@rustbot` label F-inherent_associated_types r? `@compiler-errors`
2 parents ea6ac45 + 434f088 commit d2823a1

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,12 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
506506
| ty::Param(_)
507507
| ty::Placeholder(..)
508508
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
509+
| ty::Alias(ty::Inherent, _)
509510
| ty::Error(_) => return,
510511
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
511512
| ty::Bound(..) => bug!("unexpected self type for `{goal:?}`"),
512-
ty::Alias(_, alias_ty) => alias_ty,
513+
// Excluding IATs here as they don't have meaningful item bounds.
514+
ty::Alias(ty::Projection | ty::Opaque, alias_ty) => alias_ty,
513515
};
514516

515517
for assumption in self.tcx().item_bounds(alias_ty.def_id).subst(self.tcx(), alias_ty.substs)

compiler/rustc_trait_selection/src/traits/project.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,10 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
15431543
// Check whether the self-type is itself a projection.
15441544
// If so, extract what we know from the trait and try to come up with a good answer.
15451545
let bounds = match *obligation.predicate.self_ty().kind() {
1546-
ty::Alias(_, ref data) => tcx.item_bounds(data.def_id).subst(tcx, data.substs),
1546+
// Excluding IATs here as they don't have meaningful item bounds.
1547+
ty::Alias(ty::Projection | ty::Opaque, ref data) => {
1548+
tcx.item_bounds(data.def_id).subst(tcx, data.substs)
1549+
}
15471550
ty::Infer(ty::TyVar(_)) => {
15481551
// If the self-type is an inference variable, then it MAY wind up
15491552
// being a projected type, so induce an ambiguity.

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
143143
// Before we go into the whole placeholder thing, just
144144
// quickly check if the self-type is a projection at all.
145145
match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
146-
ty::Alias(..) => {}
146+
// Excluding IATs here as they don't have meaningful item bounds.
147+
ty::Alias(ty::Projection | ty::Opaque, _) => {}
147148
ty::Infer(ty::TyVar(_)) => {
148149
span_bug!(
149150
obligation.cause.span,

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
156156
let placeholder_self_ty = placeholder_trait_predicate.self_ty();
157157
let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
158158
let (def_id, substs) = match *placeholder_self_ty.kind() {
159-
ty::Alias(_, ty::AliasTy { def_id, substs, .. }) => (def_id, substs),
159+
// Excluding IATs here as they don't have meaningful item bounds.
160+
ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
161+
(def_id, substs)
162+
}
160163
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
161164
};
162165

compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16451645

16461646
let tcx = self.infcx.tcx;
16471647
let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() {
1648-
ty::Alias(_, ty::AliasTy { def_id, substs, .. }) => (def_id, substs),
1648+
ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
1649+
(def_id, substs)
1650+
}
16491651
_ => {
16501652
span_bug!(
16511653
obligation.cause.span,
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(inherent_associated_types)]
2+
#![allow(incomplete_features)]
3+
4+
// Check that rustc doesn't crash on the trait bound `Self::Ty: std::marker::Freeze`.
5+
6+
pub struct Struct;
7+
8+
impl Struct {
9+
pub type Ty = usize;
10+
pub const CT: Self::Ty = 42;
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)