Skip to content

Commit 0a88339

Browse files
committed
Don't ICE for kind mismatches during error rendering
1 parent 4f75d67 commit 0a88339

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-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
{
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! This test used to ICE in typeck because of the type/const mismatch,
2+
//! even though wfcheck already errored.
3+
//! issue: rust-lang/rust#123457
4+
5+
pub struct KeyHolder<const K: u8> {}
6+
7+
pub trait ContainsKey<const K: u8> {}
8+
9+
pub trait SubsetExcept<P> {}
10+
11+
impl<K> ContainsKey<K> for KeyHolder<K> {}
12+
//~^ ERROR: type provided when a constant was expected
13+
//~| ERROR: type provided when a constant was expected
14+
15+
impl<P, T: ContainsKey<0>> SubsetExcept<P> for T {}
16+
17+
pub fn remove_key<K, S: SubsetExcept<K>>() -> S {
18+
loop {}
19+
}
20+
21+
fn main() {
22+
let map: KeyHolder<0> = remove_key::<_, _>();
23+
//~^ ERROR: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied
24+
}
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:11: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:11: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:22: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:15: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:17: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)