Skip to content

Commit 376ff5d

Browse files
committed
Fix missing value for constant ICE
1 parent d5a2707 commit 376ff5d

File tree

6 files changed

+85
-19
lines changed

6 files changed

+85
-19
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ pub fn is_const_evaluatable<'tcx>(
141141
NotConstEvaluatable::MentionsInfer
142142
} else if uv.has_non_region_param() {
143143
NotConstEvaluatable::MentionsParam
144+
} else if tcx.instantiate_and_check_impossible_predicates((uv.def, uv.args)) {
145+
return Ok(());
144146
} else {
145147
let guar = infcx.dcx().span_delayed_bug(
146148
span,

tests/crashes/135617.rs

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ check-pass
2+
3+
// Split out from `impossible_preds_repeat_expr_hack` to allow for delay span bugs to ICE
4+
5+
pub trait Unimplemented<'a> {}
6+
7+
trait Trait<T>
8+
where
9+
for<'a> T: Unimplemented<'a>,
10+
{
11+
const ASSOC: usize;
12+
}
13+
14+
impl<T> Trait<T> for u8
15+
where
16+
for<'a> T: Unimplemented<'a>,
17+
{
18+
const ASSOC: usize = 1;
19+
}
20+
21+
pub fn impossible_preds_repeat_expr_count()
22+
where
23+
for<'a> (): Unimplemented<'a>,
24+
{
25+
// This won't actually be an error in the future but we can't really determine that
26+
let _b = [(); 1 + 1];
27+
//~^ WARN: cannot use constants which depend on trivially-false where clauses
28+
//~| WARN: this was previously accepted by the compiler
29+
}
30+
31+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: cannot use constants which depend on trivially-false where clauses
2+
--> $DIR/impossible_preds_repeat_expr_hack-2.rs:26:19
3+
|
4+
LL | let _b = [(); 1 + 1];
5+
| ^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
9+
= note: `#[warn(const_evaluatable_unchecked)]` on by default
10+
11+
warning: 1 warning emitted
12+

tests/ui/const-generics/backcompat/impossible_preds_repeat_expr_hack.rs

+16
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,26 @@ pub fn impossible_preds_repeat_expr_count()
2222
where
2323
for<'a> (): Unimplemented<'a>,
2424
{
25+
// I expect this to potentially compile with MGCA (maybe)
26+
let _a = [(); <u8 as Trait<()>>::ASSOC];
27+
//~^ WARN: cannot use constants which depend on trivially-false where clauses
28+
//~| WARN: this was previously accepted by the compiler
29+
30+
// evaluating the anon const requires evaluating an assoc const which fails even though
31+
// we "best effort" try to allow evaluating repeat exprs still. this prevents equating
32+
// `1` with the anon const.
33+
//
34+
// I expect this to potentially compile with MGCA (maybe)
2535
let _a: [(); 1] = [(); <u8 as Trait<()>>::ASSOC];
2636
//~^ WARN: cannot use constants which depend on trivially-false where clauses
2737
//~| WARN: this was previously accepted by the compiler
2838
//~^^^ ERROR: mismatched types
39+
40+
// This will just compiling in the future and not be an error but it's hard to
41+
// detect this until making the FCW a hard error
42+
let _c: [(); 2] = [(); 1 + 1];
43+
//~^ WARN: cannot use constants which depend on trivially-false where clauses
44+
//~| WARN: this was previously accepted by the compiler
2945
}
3046

3147
struct Foo<const N: usize>;

tests/ui/const-generics/backcompat/impossible_preds_repeat_expr_hack.stderr

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11
warning: cannot use constants which depend on trivially-false where clauses
2-
--> $DIR/impossible_preds_repeat_expr_hack.rs:25:28
2+
--> $DIR/impossible_preds_repeat_expr_hack.rs:26:19
3+
|
4+
LL | let _a = [(); <u8 as Trait<()>>::ASSOC];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
9+
= note: `#[warn(const_evaluatable_unchecked)]` on by default
10+
11+
warning: cannot use constants which depend on trivially-false where clauses
12+
--> $DIR/impossible_preds_repeat_expr_hack.rs:35:28
313
|
414
LL | let _a: [(); 1] = [(); <u8 as Trait<()>>::ASSOC];
515
| ^^^^^^^^^^^^^^^^^^^^^^^^
616
|
717
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
818
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
9-
= note: `#[warn(const_evaluatable_unchecked)]` on by default
1019

1120
error[E0308]: mismatched types
12-
--> $DIR/impossible_preds_repeat_expr_hack.rs:25:23
21+
--> $DIR/impossible_preds_repeat_expr_hack.rs:35:23
1322
|
1423
LL | let _a: [(); 1] = [(); <u8 as Trait<()>>::ASSOC];
1524
| ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an array with a size of 1, found one with a size of <u8 as Trait<()>>::ASSOC
1625
| |
1726
| expected due to this
1827

28+
warning: cannot use constants which depend on trivially-false where clauses
29+
--> $DIR/impossible_preds_repeat_expr_hack.rs:42:28
30+
|
31+
LL | let _c: [(); 2] = [(); 1 + 1];
32+
| ^^^^^
33+
|
34+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
35+
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
36+
1937
error[E0277]: the trait bound `for<'a> (): Unimplemented<'a>` is not satisfied
20-
--> $DIR/impossible_preds_repeat_expr_hack.rs:37:43
38+
--> $DIR/impossible_preds_repeat_expr_hack.rs:53:43
2139
|
2240
LL | let _a: Foo<1> = Foo::<{ <u8 as Trait<()>>::ASSOC }>;
2341
| ^^ the trait `for<'a> Unimplemented<'a>` is not implemented for `()`
@@ -37,7 +55,7 @@ LL | const ASSOC: usize;
3755
| ----- required by a bound in this associated constant
3856

3957
error[E0277]: the trait bound `for<'a> (): Unimplemented<'a>` is not satisfied
40-
--> $DIR/impossible_preds_repeat_expr_hack.rs:37:31
58+
--> $DIR/impossible_preds_repeat_expr_hack.rs:53:31
4159
|
4260
LL | let _a: Foo<1> = Foo::<{ <u8 as Trait<()>>::ASSOC }>;
4361
| ^^ the trait `for<'a> Unimplemented<'a>` is not implemented for `()`
@@ -56,7 +74,7 @@ LL | where
5674
LL | for<'a> T: Unimplemented<'a>,
5775
| ----------------- unsatisfied trait bound introduced here
5876

59-
error: aborting due to 3 previous errors; 1 warning emitted
77+
error: aborting due to 3 previous errors; 3 warnings emitted
6078

6179
Some errors have detailed explanations: E0277, E0308.
6280
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)