Skip to content

Commit dc70e28

Browse files
committed
Don't ICE for kind mismatches during error rendering
1 parent 8be85d5 commit dc70e28

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19741974
for (obligation_arg, impl_arg) in
19751975
std::iter::zip(obligation_trait_ref.args, impl_trait_ref.args)
19761976
{
1977+
if (obligation_arg, impl_arg).references_error() {
1978+
return false;
1979+
}
19771980
if let Err(terr) =
19781981
ocx.eq(&ObligationCause::dummy(), param_env, impl_arg, obligation_arg)
19791982
{
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! THis test used to ICE in typeck because of the type/const mismatch,
2+
//! even though wfcheck already errored.
3+
4+
pub struct KeyHolder<const K: u8> {}
5+
6+
pub trait ContainsKey<const K: u8> {}
7+
8+
pub trait SubsetExcept<P> {}
9+
10+
impl<K> ContainsKey<K> for KeyHolder<K> {}
11+
//~^ ERROR: type provided when a constant was expected
12+
//~| ERROR: type provided when a constant was expected
13+
14+
impl<P, T: ContainsKey<0>> SubsetExcept<P> for T {}
15+
16+
pub fn remove_key<K, S: SubsetExcept<K>>() -> S {
17+
loop {}
18+
}
19+
20+
fn main() {
21+
let map: KeyHolder<0> = remove_key::<_, _>();
22+
//~^ ERROR: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0747]: type provided when a constant was expected
2+
--> $DIR/kind_mismatch.rs:10:38
3+
|
4+
LL | impl<K> ContainsKey<K> for KeyHolder<K> {}
5+
| - ^
6+
| |
7+
| help: consider changing this type parameter to a const parameter: `const K: u8`
8+
9+
error[E0747]: type provided when a constant was expected
10+
--> $DIR/kind_mismatch.rs:10:21
11+
|
12+
LL | impl<K> ContainsKey<K> for KeyHolder<K> {}
13+
| - ^
14+
| |
15+
| help: consider changing this type parameter to a const parameter: `const K: u8`
16+
17+
error[E0277]: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied
18+
--> $DIR/kind_mismatch.rs:21:45
19+
|
20+
LL | let map: KeyHolder<0> = remove_key::<_, _>();
21+
| ^ the trait `ContainsKey<0>` is not implemented for `KeyHolder<0>`, which is required by `KeyHolder<0>: SubsetExcept<_>`
22+
|
23+
note: required for `KeyHolder<0>` to implement `SubsetExcept<_>`
24+
--> $DIR/kind_mismatch.rs:14:28
25+
|
26+
LL | impl<P, T: ContainsKey<0>> SubsetExcept<P> for T {}
27+
| -------------- ^^^^^^^^^^^^^^^ ^
28+
| |
29+
| unsatisfied trait bound introduced here
30+
note: required by a bound in `remove_key`
31+
--> $DIR/kind_mismatch.rs:16:25
32+
|
33+
LL | pub fn remove_key<K, S: SubsetExcept<K>>() -> S {
34+
| ^^^^^^^^^^^^^^^ required by this bound in `remove_key`
35+
36+
error: aborting due to 3 previous errors
37+
38+
Some errors have detailed explanations: E0277, E0747.
39+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)