-
-
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
a055c7c
7c52368
d8cd4cc
1f9a514
1240be2
2e34f41
e8390d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,11 +63,11 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Par | |
| fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool { | ||
| match p.kind().skip_binder() { | ||
| ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..)) | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..)) => false, | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..)) | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..)) => false, | ||
|
Member
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. oh this is slightly scuffed actually 🤔 we probably don't to change this but then I guess can you revert this and then instead of registering the
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 change results in a more sensible error message being emitted in the |
||
| ty::PredicateKind::Clause(ty::ClauseKind::Trait(..)) | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::Projection(..)) | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..)) | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_)) | ||
| | ty::PredicateKind::NormalizesTo(..) | ||
| | ty::PredicateKind::AliasRelate(..) | ||
|
|
||
| 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() {} |
| 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`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| error: the constant `"this isn't a usize"` is not of type `usize` | ||
| --> $DIR/type-const-free-value-type-mismatch.rs:10:1 | ||
| | | ||
| LL | type const N: usize = "this isn't a usize"; | ||
| | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` | ||
|
|
||
| error[E0080]: transmuting from $BYTE-byte type to $BYTE-byte type: `&str` -> `usize` | ||
| --> $DIR/type-const-free-value-type-mismatch.rs:13:24 | ||
| | | ||
| LL | fn f() -> [u8; const { N }] {} | ||
| | ^ evaluation of `f::{constant#0}` failed here | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0080`. |
| 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:10: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:13:11 | ||
| | | ||
| LL | fn f() -> [u8; const { N }] {} | ||
| | ^^^^^^^^^^^^^^^^^ cannot normalize `f::{constant#0}` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/type-const-free-value-type-mismatch.rs:13: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`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #![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 | ||
| //@ normalize-stderr: "\d+-byte" -> "$$BYTE-byte" | ||
|
|
||
| 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 transmuting from | ||
| //[next]~^^ ERROR type annotations needed | ||
| //[next]~| ERROR mismatched types [E0308] | ||
|
|
||
| fn main() {} |
| 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`. |
| 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`. |
| 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() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| error[E0053]: method `arr` has an incompatible type for trait | ||
| --> $DIR/type-const-value-type-mismatch.rs:22:5 | ||
| | | ||
| LL | fn arr() -> [u8; const { Self::LEN }] {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an array with a size of 0, found one with a size of const { Self::LEN } | ||
| | | ||
| note: type in trait | ||
| --> $DIR/type-const-value-type-mismatch.rs:15:5 | ||
| | | ||
| LL | fn arr() -> [u8; Self::LEN]; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| = note: expected signature `fn() -> [u8; 0]` | ||
| found signature `fn() -> [u8; const { Self::LEN }]` | ||
|
|
||
| error: the constant `0` is not of type `usize` | ||
| --> $DIR/type-const-value-type-mismatch.rs:19:5 | ||
| | | ||
| LL | type const LEN: usize = 0u8; | ||
| | ^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u8` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/type-const-value-type-mismatch.rs:22:17 | ||
| | | ||
| LL | fn arr() -> [u8; const { Self::LEN }] {} | ||
| | --- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; const { Self::LEN }]`, found `()` | ||
| | | | ||
| | implicitly returns `()` as its body has no tail or `return` expression | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0053, E0308. | ||
| For more information about an error, try `rustc --explain E0053`. |
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