Skip to content

Commit 1614b7f

Browse files
estebankMark-Simulacrum
authored andcommitted
Do not ICE with TraitPredicates containing [type error]
Fix #77919.
1 parent 49c5862 commit 1614b7f

File tree

3 files changed

+72
-6
lines changed

3 files changed

+72
-6
lines changed

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -1951,12 +1951,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19511951
&predicate.subst(tcx, substs),
19521952
&mut obligations,
19531953
);
1954-
obligations.push(Obligation {
1955-
cause: cause.clone(),
1956-
recursion_depth,
1957-
param_env,
1958-
predicate,
1959-
});
1954+
if predicate.references_error() {
1955+
self.tcx().sess.delay_span_bug(
1956+
cause.span,
1957+
&format!("impl_or_trait_obligation with errors: {:?}", predicate),
1958+
);
1959+
} else {
1960+
obligations.push(Obligation {
1961+
cause: cause.clone(),
1962+
recursion_depth,
1963+
param_env,
1964+
predicate,
1965+
});
1966+
}
19601967
}
19611968

19621969
// We are performing deduplication here to avoid exponential blowups

src/test/ui/issues/issue-77919.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main() {
2+
[1; <Multiply<Five, Five>>::VAL]; //~ ERROR evaluation of constant value failed
3+
}
4+
trait TypeVal<T> {
5+
const VAL: T; //~ ERROR any use of this value will cause an error
6+
}
7+
struct Five;
8+
struct Multiply<N, M> {
9+
_n: PhantomData, //~ ERROR cannot find type `PhantomData` in this scope
10+
}
11+
impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
12+
//~^ ERROR cannot find type `VAL` in this scope
13+
//~| ERROR not all trait items implemented, missing: `VAL`

src/test/ui/issues/issue-77919.stderr

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error[E0412]: cannot find type `PhantomData` in this scope
2+
--> $DIR/issue-77919.rs:9:9
3+
|
4+
LL | _n: PhantomData,
5+
| ^^^^^^^^^^^ not found in this scope
6+
|
7+
help: consider importing this struct
8+
|
9+
LL | use std::marker::PhantomData;
10+
|
11+
12+
error[E0412]: cannot find type `VAL` in this scope
13+
--> $DIR/issue-77919.rs:11:63
14+
|
15+
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
16+
| - ^^^ not found in this scope
17+
| |
18+
| help: you might be missing a type parameter: `, VAL`
19+
20+
error[E0046]: not all trait items implemented, missing: `VAL`
21+
--> $DIR/issue-77919.rs:11:1
22+
|
23+
LL | const VAL: T;
24+
| ------------- `VAL` from trait
25+
...
26+
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation
28+
29+
error: any use of this value will cause an error
30+
--> $DIR/issue-77919.rs:5:5
31+
|
32+
LL | const VAL: T;
33+
| ^^^^^^^^^^^^^ no MIR body is available for DefId(0:7 ~ issue_77919[317d]::TypeVal::VAL)
34+
|
35+
= note: `#[deny(const_err)]` on by default
36+
37+
error[E0080]: evaluation of constant value failed
38+
--> $DIR/issue-77919.rs:2:9
39+
|
40+
LL | [1; <Multiply<Five, Five>>::VAL];
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
42+
43+
error: aborting due to 5 previous errors
44+
45+
Some errors have detailed explanations: E0046, E0080, E0412.
46+
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)