-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
mgca: Register ConstArgHasType when normalizing projection consts
#154853
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
7
commits into
rust-lang:main
Choose a base branch
from
lapla-cogito:normlize_projecttion_const
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.
+366
−8
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a055c7c
Register `ConstArgHasType` obligation when normalizing trait projecti…
lapla-cogito 7c52368
Register `ConstArgHasType` obligation when normalizing inherent proje…
lapla-cogito d8cd4cc
Add test that free type const value type mismatch does not ICE
lapla-cogito 1f9a514
Extract shared helper for registering `ConstArgHasType` during const …
lapla-cogito 1240be2
Register `ConstArgHasType` when normalizing free const aliases
lapla-cogito 2e34f41
Make `instantiate_normalizes_to_term()` also handle `ConstArgHasType`…
lapla-cogito e8390d8
Register `ConstArgHasType` in queries
lapla-cogito 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
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
12 changes: 12 additions & 0 deletions
12
tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.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,12 @@ | ||
| //@ compile-flags: -Zvalidate-mir -Znext-solver | ||
|
|
||
| #![feature(min_generic_const_args)] | ||
| #![expect(incomplete_features)] | ||
|
|
||
| type const X: usize = const { N }; | ||
| //~^ ERROR type annotations needed | ||
|
|
||
| type const N: usize = "this isn't a usize"; | ||
| //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` | ||
|
|
||
| fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.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[E0284]: type annotations needed: cannot normalize `X::{constant#0}` | ||
| --> $DIR/type-const-free-anon-const-mismatch.rs:6:1 | ||
| | | ||
| LL | type const X: usize = const { N }; | ||
| | ^^^^^^^^^^^^^^^^^^^ cannot normalize `X::{constant#0}` | ||
|
|
||
| error: the constant `"this isn't a usize"` is not of type `usize` | ||
| --> $DIR/type-const-free-anon-const-mismatch.rs:9:1 | ||
| | | ||
| LL | type const N: usize = "this isn't a usize"; | ||
| | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0284`. |
17 changes: 17 additions & 0 deletions
17
tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.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,17 @@ | ||
| error: the constant `"this isn't a usize"` is not of type `usize` | ||
| --> $DIR/type-const-free-value-type-mismatch.rs:9:1 | ||
| | | ||
| LL | type const N: usize = "this isn't a usize"; | ||
| | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/type-const-free-value-type-mismatch.rs:12:11 | ||
| | | ||
| LL | fn f() -> [u8; const { N }] {} | ||
| | - ^^^^^^^^^^^^^^^^^ expected `[u8; const { N }]`, found `()` | ||
| | | | ||
| | implicitly returns `()` as its body has no tail or `return` expression | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0308`. |
24 changes: 24 additions & 0 deletions
24
tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.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,24 @@ | ||
| error: the constant `"this isn't a usize"` is not of type `usize` | ||
| --> $DIR/type-const-free-value-type-mismatch.rs:9:1 | ||
| | | ||
| LL | type const N: usize = "this isn't a usize"; | ||
| | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` | ||
|
|
||
| error[E0284]: type annotations needed: cannot normalize `f::{constant#0}` | ||
| --> $DIR/type-const-free-value-type-mismatch.rs:12:11 | ||
| | | ||
| LL | fn f() -> [u8; const { N }] {} | ||
| | ^^^^^^^^^^^^^^^^^ cannot normalize `f::{constant#0}` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/type-const-free-value-type-mismatch.rs:12:11 | ||
| | | ||
| LL | fn f() -> [u8; const { N }] {} | ||
| | - ^^^^^^^^^^^^^^^^^ expected `[u8; _]`, found `()` | ||
| | | | ||
| | implicitly returns `()` as its body has no tail or `return` expression | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0284, E0308. | ||
| For more information about an error, try `rustc --explain E0284`. |
17 changes: 17 additions & 0 deletions
17
tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.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,17 @@ | ||
| #![feature(min_generic_const_args)] | ||
| #![expect(incomplete_features)] | ||
|
|
||
| //@ revisions: current next | ||
| //@ ignore-compare-mode-next-solver (explicit revisions) | ||
| //@[next] compile-flags: -Znext-solver | ||
| //@ compile-flags: -Zvalidate-mir | ||
|
|
||
| type const N: usize = "this isn't a usize"; | ||
| //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` | ||
|
|
||
| fn f() -> [u8; const { N }] {} | ||
| //[current]~^ ERROR mismatched types [E0308] | ||
| //[next]~^^ ERROR type annotations needed | ||
| //[next]~| ERROR mismatched types [E0308] | ||
|
|
||
| fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.current.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,17 @@ | ||
| error: the constant `"this isn't a usize"` is not of type `usize` | ||
| --> $DIR/type-const-inherent-value-type-mismatch.rs:14:5 | ||
| | | ||
| LL | type const N: usize = "this isn't a usize"; | ||
| | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/type-const-inherent-value-type-mismatch.rs:18:11 | ||
| | | ||
| LL | fn f() -> [u8; const { Struct::N }] {} | ||
| | - ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; const { Struct::N }]`, found `()` | ||
| | | | ||
| | implicitly returns `()` as its body has no tail or `return` expression | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0308`. |
24 changes: 24 additions & 0 deletions
24
tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.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,24 @@ | ||
| error[E0284]: type annotations needed: cannot normalize `f::{constant#0}` | ||
| --> $DIR/type-const-inherent-value-type-mismatch.rs:18:11 | ||
| | | ||
| LL | fn f() -> [u8; const { Struct::N }] {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot normalize `f::{constant#0}` | ||
|
|
||
| error: the constant `"this isn't a usize"` is not of type `usize` | ||
| --> $DIR/type-const-inherent-value-type-mismatch.rs:14:5 | ||
| | | ||
| LL | type const N: usize = "this isn't a usize"; | ||
| | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/type-const-inherent-value-type-mismatch.rs:18:11 | ||
| | | ||
| LL | fn f() -> [u8; const { Struct::N }] {} | ||
| | - ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; _]`, found `()` | ||
| | | | ||
| | implicitly returns `()` as its body has no tail or `return` expression | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0284, E0308. | ||
| For more information about an error, try `rustc --explain E0284`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.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 @@ | ||
| // Regression test for https://github.com/rust-lang/rust/issues/152962 | ||
|
|
||
| //@ revisions: current next | ||
| //@ ignore-compare-mode-next-solver (explicit revisions) | ||
| //@[next] compile-flags: -Znext-solver | ||
| //@ compile-flags: -Zvalidate-mir | ||
|
|
||
| #![feature(min_generic_const_args)] | ||
| #![expect(incomplete_features)] | ||
|
|
||
| struct Struct; | ||
|
|
||
| impl Struct { | ||
| type const N: usize = "this isn't a usize"; | ||
| //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` | ||
| } | ||
|
|
||
| fn f() -> [u8; const { Struct::N }] {} | ||
| //~^ ERROR mismatched types [E0308] | ||
| //[next]~| ERROR type annotations needed | ||
|
|
||
| fn main() {} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
sorry for butting in kinda late - some optional feedback here:
The way that I would expect this to work is that things are wfchecked at definition site before they're attempted to be evaluated (and so would be tainted, and this usage would never even get to this point of attempting to normalize it). You write in the PR description:
I presume there is some cursed arcane reason why we cannot easily fix the "due to query evaluation ordering" part of that sentence, and why this approach of slapping on ConstArgHasType obligations to the normalization result is needed.
Would you mind writing that cursed arcane reason into a comment here? I find comments of the style "hey reader, you're not insane, this is indeed wonky and not what you would expect, because [...]" to be extremely helpful ❤️
View changes since the review