-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #109336 - compiler-errors:constrain-to-ct-err, r=BoxyUwU
Constrain const vars to error if const types are mismatched When equating two consts of different types, if either are const variables, constrain them to the correct const error kind. This helps us avoid "successfully" matching a const against an impl signature but leaving unconstrained const vars, which will lead to incremental ICEs when we call const-eval queries during const projection. Fixes #109296 The second commit in the stack fixes a regression in the first commit where we end up mentioning `[const error]` in an impl overlap error message. I think the error message changes for the better, but I could implement alternative strategies to avoid this without delaying the overlap error message... r? `@BoxyUwU`
- Loading branch information
Showing
6 changed files
with
51 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// incremental | ||
#![crate_type = "lib"] | ||
|
||
trait Q { | ||
const ASSOC: usize; | ||
} | ||
|
||
impl<const N: u64> Q for [u8; N] { | ||
//~^ ERROR mismatched types | ||
const ASSOC: usize = 1; | ||
} | ||
|
||
pub fn test() -> [u8; <[u8; 13] as Q>::ASSOC] { todo!() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/bad-subst-const-kind.rs:8:31 | ||
| | ||
LL | impl<const N: u64> Q for [u8; N] { | ||
| ^ expected `usize`, found `u64` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
error[E0119]: conflicting implementations of trait `Copy` for type `S<_>` | ||
--> $DIR/bad-const-wf-doesnt-specialize.rs:9:1 | ||
error: the constant `N` is not of type `usize` | ||
--> $DIR/bad-const-wf-doesnt-specialize.rs:8:29 | ||
| | ||
LL | impl<const N: i32> Copy for S<N> {} | ||
| -------------------------------- first implementation here | ||
LL | impl<const M: usize> Copy for S<M> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `S<_>` | ||
| ^^^^ | ||
| | ||
note: required by a bound in `S` | ||
--> $DIR/bad-const-wf-doesnt-specialize.rs:6:10 | ||
| | ||
LL | struct S<const L: usize>; | ||
| ^^^^^^^^^^^^^^ required by this bound in `S` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0119`. |