Skip to content

Commit f60b749

Browse files
Do not assume child bound assumptions for rigid alias
1 parent dee7d0e commit f60b749

File tree

7 files changed

+92
-16
lines changed

7 files changed

+92
-16
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
345345
self.item_bounds(def_id).map_bound(IntoIterator::into_iter)
346346
}
347347

348+
fn item_self_bounds(
349+
self,
350+
def_id: DefId,
351+
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
352+
self.item_super_predicates(def_id).map_bound(IntoIterator::into_iter)
353+
}
354+
355+
fn item_non_self_bounds(
356+
self,
357+
def_id: DefId,
358+
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
359+
self.item_non_self_assumptions(def_id).map_bound(IntoIterator::into_iter)
360+
}
361+
348362
fn predicates_of(
349363
self,
350364
def_id: DefId,

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,12 @@ where
510510
candidates: &mut Vec<Candidate<I>>,
511511
) {
512512
let () = self.probe(|_| ProbeKind::NormalizedSelfTyAssembly).enter(|ecx| {
513-
ecx.assemble_alias_bound_candidates_recur(goal.predicate.self_ty(), goal, candidates);
513+
ecx.assemble_alias_bound_candidates_recur(
514+
goal.predicate.self_ty(),
515+
goal,
516+
candidates,
517+
true,
518+
);
514519
});
515520
}
516521

@@ -528,6 +533,7 @@ where
528533
self_ty: I::Ty,
529534
goal: Goal<I, G>,
530535
candidates: &mut Vec<Candidate<I>>,
536+
is_self: bool,
531537
) {
532538
let (kind, alias_ty) = match self_ty.kind() {
533539
ty::Bool
@@ -580,16 +586,34 @@ where
580586
}
581587
};
582588

583-
for assumption in
584-
self.cx().item_bounds(alias_ty.def_id).iter_instantiated(self.cx(), alias_ty.args)
585-
{
586-
candidates.extend(G::probe_and_consider_implied_clause(
587-
self,
588-
CandidateSource::AliasBound,
589-
goal,
590-
assumption,
591-
[],
592-
));
589+
if is_self {
590+
for assumption in self
591+
.cx()
592+
.item_self_bounds(alias_ty.def_id)
593+
.iter_instantiated(self.cx(), alias_ty.args)
594+
{
595+
candidates.extend(G::probe_and_consider_implied_clause(
596+
self,
597+
CandidateSource::AliasBound,
598+
goal,
599+
assumption,
600+
[],
601+
));
602+
}
603+
} else {
604+
for assumption in self
605+
.cx()
606+
.item_non_self_bounds(alias_ty.def_id)
607+
.iter_instantiated(self.cx(), alias_ty.args)
608+
{
609+
candidates.extend(G::probe_and_consider_implied_clause(
610+
self,
611+
CandidateSource::AliasBound,
612+
goal,
613+
assumption,
614+
[],
615+
));
616+
}
593617
}
594618

595619
candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty));
@@ -601,7 +625,7 @@ where
601625
// Recurse on the self type of the projection.
602626
match self.structurally_normalize_ty(goal.param_env, alias_ty.self_ty()) {
603627
Ok(next_self_ty) => {
604-
self.assemble_alias_bound_candidates_recur(next_self_ty, goal, candidates)
628+
self.assemble_alias_bound_candidates_recur(next_self_ty, goal, candidates, false)
605629
}
606630
Err(NoSolution) => {}
607631
}

compiler/rustc_type_ir/src/interner.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ pub trait Interner:
203203
def_id: Self::DefId,
204204
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
205205

206+
fn item_self_bounds(
207+
self,
208+
def_id: Self::DefId,
209+
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
210+
211+
fn item_non_self_bounds(
212+
self,
213+
def_id: Self::DefId,
214+
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
215+
206216
fn predicates_of(
207217
self,
208218
def_id: Self::DefId,

tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.stderr renamed to tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.current.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0382]: use of moved value: `x`
2-
--> $DIR/cant-see-copy-bound-from-child-rigid.rs:14:9
2+
--> $DIR/cant-see-copy-bound-from-child-rigid.rs:18:9
33
|
44
LL | fn foo<T: Trait>(x: T::Assoc) -> (T::Assoc, T::Assoc)
55
| - move occurs because `x` has type `<T as Trait>::Assoc`, which does not implement the `Copy` trait
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0382]: use of moved value: `x`
2+
--> $DIR/cant-see-copy-bound-from-child-rigid.rs:18:9
3+
|
4+
LL | fn foo<T: Trait>(x: T::Assoc) -> (T::Assoc, T::Assoc)
5+
| - move occurs because `x` has type `<T as Trait>::Assoc`, which does not implement the `Copy` trait
6+
...
7+
LL | (x, x)
8+
| - ^ value used here after move
9+
| |
10+
| value moved here
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0382`.

tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
15
trait Id {
26
type This: ?Sized;
37
}

tests/ui/traits/const-traits/const-impl-trait.stderr

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ note: `PartialEq` can't be used with `~const` because it isn't annotated with `#
9999
--> $SRC_DIR/core/src/cmp.rs:LL:COL
100100
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
101101

102+
error: `~const` can only be applied to `#[const_trait]` traits
103+
--> $DIR/const-impl-trait.rs:27:22
104+
|
105+
LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy {
106+
| ^^^^^^ can't be applied to `PartialEq`
107+
|
108+
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
109+
--> $SRC_DIR/core/src/cmp.rs:LL:COL
110+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
111+
102112
error: `~const` can only be applied to `#[const_trait]` traits
103113
--> $DIR/const-impl-trait.rs:23:22
104114
|
@@ -120,9 +130,9 @@ note: `PartialEq` can't be used with `~const` because it isn't annotated with `#
120130
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
121131

122132
error: `~const` can only be applied to `#[const_trait]` traits
123-
--> $DIR/const-impl-trait.rs:27:22
133+
--> $DIR/const-impl-trait.rs:23:22
124134
|
125-
LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy {
135+
LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy;
126136
| ^^^^^^ can't be applied to `PartialEq`
127137
|
128138
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
@@ -181,7 +191,7 @@ LL | a == a
181191
|
182192
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
183193

184-
error: aborting due to 20 previous errors
194+
error: aborting due to 21 previous errors
185195

186196
Some errors have detailed explanations: E0015, E0635.
187197
For more information about an error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)