Skip to content

Commit 7629908

Browse files
Make unnormalizable item ambiguous in coherence
1 parent a1dc702 commit 7629908

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,23 @@ where
238238
// delay a bug because we can have trivially false where clauses, so we
239239
// treat it as rigid.
240240
if cx.impl_self_is_guaranteed_unsized(impl_def_id) {
241-
ecx.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias);
242-
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
241+
match ecx.typing_mode() {
242+
ty::TypingMode::Coherence => {
243+
return ecx.evaluate_added_goals_and_make_canonical_response(
244+
Certainty::AMBIGUOUS,
245+
);
246+
}
247+
ty::TypingMode::Analysis { .. }
248+
| ty::TypingMode::PostBorrowckAnalysis { .. }
249+
| ty::TypingMode::PostAnalysis => {
250+
ecx.structurally_instantiate_normalizes_to_term(
251+
goal,
252+
goal.predicate.alias,
253+
);
254+
return ecx
255+
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
256+
}
257+
}
243258
} else {
244259
return error_response(ecx, cx.delay_bug("missing item"));
245260
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
struct MaybeUnsized<T: Overlap<U>, U>(<T as Overlap<U>>::MaybeUnsized);
2+
3+
trait ReqSized {
4+
type Missing1
5+
where
6+
Self: Sized;
7+
type Missing2
8+
where
9+
Self: Sized;
10+
}
11+
impl<T> ReqSized for MaybeUnsized<T, u32> {}
12+
13+
struct W<T: ?Sized>(T);
14+
trait Eq<T> {}
15+
impl<T> Eq<T> for W<T> {}
16+
17+
trait RelateReqSized {}
18+
impl<T: ReqSized> RelateReqSized for T where W<T::Missing1>: Eq<T::Missing2> {}
19+
20+
trait Overlap<U> {
21+
type MaybeUnsized: ?Sized;
22+
}
23+
impl<T> Overlap<u32> for T {
24+
type MaybeUnsized = str;
25+
}
26+
impl<U> Overlap<U> for u32
27+
//~^ ERROR conflicting implementations of trait `Overlap<u32>` for type `u32`
28+
where
29+
MaybeUnsized<U, u32>: RelateReqSized,
30+
{
31+
type MaybeUnsized = u32;
32+
}
33+
34+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0119]: conflicting implementations of trait `Overlap<u32>` for type `u32`
2+
--> $DIR/trivial-unsized-projection-in-coherence.rs:26:1
3+
|
4+
LL | impl<T> Overlap<u32> for T {
5+
| -------------------------- first implementation here
6+
...
7+
LL | / impl<U> Overlap<U> for u32
8+
LL | |
9+
LL | | where
10+
LL | | MaybeUnsized<U, u32>: RelateReqSized,
11+
| |_________________________________________^ conflicting implementation for `u32`
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)