-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Fix ICE when a suffixed literal's type doesn't match the expected const arg type #152906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lapla-cogito
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
lapla-cogito:issue_152653
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+88
−99
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
tests/ui/const-generics/mgca/type_const-assoc-mismatched-literal-suffix.rs
This file contains hidden or 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,22 @@ | ||
| //@ compile-flags: -Zvalidate-mir | ||
|
|
||
| // Regression test for https://github.com/rust-lang/rust/issues/152962 | ||
|
|
||
| #![feature(min_generic_const_args)] | ||
| #![allow(incomplete_features)] | ||
|
|
||
| pub struct A; | ||
|
|
||
| pub trait Array { | ||
| type const LEN: usize; | ||
| fn arr() -> [u8; Self::LEN]; | ||
| } | ||
|
|
||
| impl Array for A { | ||
| type const LEN: usize = 0u8; | ||
| //~^ ERROR mismatched types | ||
|
|
||
| fn arr() -> [u8; const { Self::LEN }] {} | ||
| } | ||
|
|
||
| fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/mgca/type_const-assoc-mismatched-literal-suffix.stderr
This file contains hidden or 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,15 @@ | ||
| error[E0308]: mismatched types | ||
| --> $DIR/type_const-assoc-mismatched-literal-suffix.rs:16:29 | ||
| | | ||
| LL | type const LEN: usize = 0u8; | ||
| | ^^^ expected `usize`, found `u8` | ||
| | | ||
| help: change the type of the numeric literal from `u8` to `usize` | ||
| | | ||
| LL - type const LEN: usize = 0u8; | ||
| LL + type const LEN: usize = 0usize; | ||
| | | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0308`. |
13 changes: 13 additions & 0 deletions
13
tests/ui/const-generics/mgca/type_const-mismatched-literal-suffix.rs
This file contains hidden or 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 @@ | ||
| //@ compile-flags: --emit=link | ||
|
|
||
| // Regression test for https://github.com/rust-lang/rust/issues/152653 | ||
|
|
||
| #![feature(min_generic_const_args)] | ||
| #![expect(incomplete_features)] | ||
|
|
||
| type const CONST: usize = 1_i32; | ||
| //~^ ERROR mismatched types | ||
|
|
||
| fn main() { | ||
| CONST; | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/mgca/type_const-mismatched-literal-suffix.stderr
This file contains hidden or 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,15 @@ | ||
| error[E0308]: mismatched types | ||
| --> $DIR/type_const-mismatched-literal-suffix.rs:8:27 | ||
| | | ||
| LL | type const CONST: usize = 1_i32; | ||
| | ^^^^^ expected `usize`, found `i32` | ||
| | | ||
| help: change the type of the numeric literal from `i32` to `usize` | ||
| | | ||
| LL - type const CONST: usize = 1_i32; | ||
| LL + type const CONST: usize = 1_usize; | ||
| | | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0308`. |
This file contains hidden or 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 hidden or 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,21 +1,3 @@ | ||
| error: the constant `5` is not of type `u32` | ||
| --> $DIR/type_const-mismatched-types.rs:4:1 | ||
| | | ||
| LL | type const FREE: u32 = 5_usize; | ||
| | ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize` | ||
|
|
||
| error: the constant `5` is not of type `isize` | ||
| --> $DIR/type_const-mismatched-types.rs:8:1 | ||
| | | ||
| LL | type const FREE2: isize = FREE; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `usize` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/type_const-mismatched-types.rs:16:27 | ||
| | | ||
| LL | type const N: usize = false; | ||
| | ^^^^^ expected `usize`, found `bool` | ||
|
|
||
|
Comment on lines
-1
to
-18
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fix, as mentioned above, fixes the ICE while simultaneously reverting the seemingly redundant error output introduced in #152001 (in fact, this ICE was identified as originating from this PR in the original issue). |
||
| error[E0308]: mismatched types | ||
| --> $DIR/type_const-mismatched-types.rs:4:24 | ||
| | | ||
|
|
@@ -28,6 +10,12 @@ LL - type const FREE: u32 = 5_usize; | |
| LL + type const FREE: u32 = 5_u32; | ||
| | | ||
|
|
||
| error: aborting due to 4 previous errors | ||
| error[E0308]: mismatched types | ||
| --> $DIR/type_const-mismatched-types.rs:14:27 | ||
| | | ||
| LL | type const N: usize = false; | ||
| | ^^^^^ expected `usize`, found `bool` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0308`. | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 +1,5 @@ | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/133966> | ||
| pub struct Data([[&'static str]; 5_i32]); | ||
| //~^ ERROR the constant `5` is not of type `usize` | ||
| //~| ERROR the size for values of type `[&'static str]` cannot be known at compilation time | ||
| //~| ERROR mismatched types | ||
| //~^ ERROR mismatched types | ||
| const _: &'static Data = unsafe { &*(&[] as *const Data) }; | ||
| //~^ ERROR the type `[[&str]; 5]` has an unknown layout | ||
| fn main() {} |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was required to perform MIR analysis.