Skip to content

Commit 47911eb

Browse files
Don't ICE on pending obligations from deep normalization in a loop
1 parent 191df20 commit 47911eb

File tree

4 files changed

+163
-14
lines changed

4 files changed

+163
-14
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/normalize.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ impl<'tcx> At<'_, 'tcx> {
7777
.into_value_registering_obligations(self.infcx, &mut *fulfill_cx);
7878
let errors = fulfill_cx.select_all_or_error(self.infcx);
7979
let value = self.infcx.resolve_vars_if_possible(value);
80-
if errors.is_empty() { Ok(value) } else { Err(errors) }
80+
if errors.is_empty() {
81+
Ok(value)
82+
} else {
83+
// Drop pending obligations, since deep normalization may happen
84+
// in a loop and we don't want to trigger the assertion on the next
85+
// iteration due to pending ambiguous obligations we've left over.
86+
let _ = fulfill_cx.collect_remaining_errors(self.infcx);
87+
Err(errors)
88+
}
8189
}
8290
}
8391
}

Diff for: tests/crashes/133868.rs

-13
This file was deleted.

Diff for: tests/ui/traits/deep-norm-pending.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
trait Foo {
2+
type Assoc;
3+
}
4+
5+
trait Bar {
6+
fn method() -> impl Sized;
7+
//~^ ERROR the trait bound `T: Foo` is not satisfied
8+
}
9+
impl<T> Bar for T
10+
//~^ ERROR the trait bound `T: Foo` is not satisfied
11+
//~| ERROR the trait bound `T: Foo` is not satisfied
12+
where
13+
<T as Foo>::Assoc: Sized,
14+
{
15+
fn method() {}
16+
//~^ ERROR the trait bound `T: Foo` is not satisfied
17+
//~| ERROR the trait bound `T: Foo` is not satisfied
18+
//~| ERROR the trait bound `T: Foo` is not satisfied
19+
//~| ERROR the trait bound `T: Foo` is not satisfied
20+
//~| ERROR the trait bound `T: Foo` is not satisfied
21+
//~| ERROR the trait bound `T: Foo` is not satisfied
22+
}
23+
24+
fn main() {}

Diff for: tests/ui/traits/deep-norm-pending.stderr

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
error[E0277]: the trait bound `T: Foo` is not satisfied
2+
--> $DIR/deep-norm-pending.rs:15:5
3+
|
4+
LL | fn method() {}
5+
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
6+
|
7+
help: consider further restricting type parameter `T` with trait `Foo`
8+
|
9+
LL | <T as Foo>::Assoc: Sized, T: Foo
10+
| ++++++
11+
12+
error[E0277]: the trait bound `T: Foo` is not satisfied
13+
--> $DIR/deep-norm-pending.rs:9:1
14+
|
15+
LL | / impl<T> Bar for T
16+
LL | |
17+
LL | |
18+
LL | | where
19+
LL | | <T as Foo>::Assoc: Sized,
20+
| |_____________________________^ the trait `Foo` is not implemented for `T`
21+
|
22+
help: consider further restricting type parameter `T` with trait `Foo`
23+
|
24+
LL | <T as Foo>::Assoc: Sized, T: Foo
25+
| ++++++
26+
27+
error[E0277]: the trait bound `T: Foo` is not satisfied
28+
--> $DIR/deep-norm-pending.rs:9:1
29+
|
30+
LL | / impl<T> Bar for T
31+
LL | |
32+
LL | |
33+
LL | | where
34+
... |
35+
LL | | }
36+
| |_^ the trait `Foo` is not implemented for `T`
37+
|
38+
help: consider further restricting type parameter `T` with trait `Foo`
39+
|
40+
LL | <T as Foo>::Assoc: Sized, T: Foo
41+
| ++++++
42+
43+
error[E0277]: the trait bound `T: Foo` is not satisfied
44+
--> $DIR/deep-norm-pending.rs:15:5
45+
|
46+
LL | fn method() {}
47+
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
48+
|
49+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
50+
help: consider further restricting type parameter `T` with trait `Foo`
51+
|
52+
LL | <T as Foo>::Assoc: Sized, T: Foo
53+
| ++++++
54+
55+
error[E0277]: the trait bound `T: Foo` is not satisfied
56+
--> $DIR/deep-norm-pending.rs:15:5
57+
|
58+
LL | fn method() {}
59+
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
60+
|
61+
note: required for `T` to implement `Bar`
62+
--> $DIR/deep-norm-pending.rs:9:9
63+
|
64+
LL | impl<T> Bar for T
65+
| ^^^ ^
66+
...
67+
LL | <T as Foo>::Assoc: Sized,
68+
| ----- unsatisfied trait bound introduced here
69+
help: consider further restricting type parameter `T` with trait `Foo`
70+
|
71+
LL | <T as Foo>::Assoc: Sized, T: Foo
72+
| ++++++
73+
74+
error[E0277]: the trait bound `T: Foo` is not satisfied
75+
--> $DIR/deep-norm-pending.rs:15:5
76+
|
77+
LL | fn method() {}
78+
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
79+
|
80+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
81+
help: consider further restricting type parameter `T` with trait `Foo`
82+
|
83+
LL | <T as Foo>::Assoc: Sized, T: Foo
84+
| ++++++
85+
86+
error[E0277]: the trait bound `T: Foo` is not satisfied
87+
--> $DIR/deep-norm-pending.rs:6:20
88+
|
89+
LL | fn method() -> impl Sized;
90+
| ^^^^^^^^^^ the trait `Foo` is not implemented for `T`
91+
|
92+
note: required for `T` to implement `Bar`
93+
--> $DIR/deep-norm-pending.rs:9:9
94+
|
95+
LL | impl<T> Bar for T
96+
| ^^^ ^
97+
...
98+
LL | <T as Foo>::Assoc: Sized,
99+
| ----- unsatisfied trait bound introduced here
100+
help: consider further restricting type parameter `T` with trait `Foo`
101+
|
102+
LL | <T as Foo>::Assoc: Sized, T: Foo
103+
| ++++++
104+
105+
error[E0277]: the trait bound `T: Foo` is not satisfied
106+
--> $DIR/deep-norm-pending.rs:15:5
107+
|
108+
LL | fn method() {}
109+
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
110+
|
111+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
112+
help: consider further restricting type parameter `T` with trait `Foo`
113+
|
114+
LL | <T as Foo>::Assoc: Sized, T: Foo
115+
| ++++++
116+
117+
error[E0277]: the trait bound `T: Foo` is not satisfied
118+
--> $DIR/deep-norm-pending.rs:15:8
119+
|
120+
LL | fn method() {}
121+
| ^^^^^^ the trait `Foo` is not implemented for `T`
122+
|
123+
help: consider further restricting type parameter `T` with trait `Foo`
124+
|
125+
LL | <T as Foo>::Assoc: Sized, T: Foo
126+
| ++++++
127+
128+
error: aborting due to 9 previous errors
129+
130+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)