-
Notifications
You must be signed in to change notification settings - Fork 13.4k
typeck: always expose repeat count AnonConst
s' parent in generics_of
.
#70452
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
Changes from all commits
2bbc33a
38d3834
5ebd300
ad1617b
8989029
8bb7b7b
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 |
---|---|---|
@@ -1,17 +1,10 @@ | ||
error[E0277]: the trait bound `A: Foo` is not satisfied | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/associated-const-type-parameter-arrays-2.rs:16:22 | ||
| | ||
LL | const Y: usize; | ||
| --------------- required by `Foo::Y` | ||
... | ||
LL | let _array = [4; <A as Foo>::Y]; | ||
| ^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A` | ||
| ^^^^^^^^^^^^^ | ||
| | ||
help: consider further restricting this bound | ||
| | ||
LL | pub fn test<A: Foo + Foo, B: Foo>() { | ||
| ^^^^^ | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
#![feature(const_generics)] | ||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash | ||
|
||
// build-pass | ||
|
||
fn foo<const N: usize>() { | ||
let _ = [0u64; N + 1]; | ||
//~^ ERROR constant expression depends on a generic parameter | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,13 @@ LL | #![feature(const_generics)] | |
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
warning: 1 warning emitted | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/issue-62456.rs:5:20 | ||
| | ||
LL | let _ = [0u64; N + 1]; | ||
| ^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
Comment on lines
+9
to
+15
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. I think we should improve the wording of the error. In my eyes I would prefer something along the lines of
preferably with a link to documentation, tracking issue or its own error code so that we explain why we don't support it yet and when it might be done. 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. The error is indeed misleading, because what you're suggesting isn't what the error means. The error is trying to say that evaluating the constant expression may only succeed for some "values" of the generic parameter. Note that expressions using generics can still evaluate just fine while remaining polymorphic. cc @varkor 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. I agree that this diagnostic could be improved, especially as it was misinterpreted. How about something like:
This is a bit long, though this sort of thing hopefully gets the intention across better. 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. "constant expression may not depend on a generic parameter"? (emphasis mine) 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.
(Let's not make promises. ^^)
I think we tend to prefer cannot over may not. The former is more definitive. 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. Maybe 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. But it can depend on generic parameters, the only problem is we have no guarantor for it evaluating successfully. So perhaps a better phrasing for the error itself might be "cannot prove/determine/guarantee/etc. that constant expression will evaluate successfully" and then we can search its We should also link 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. Well, I suppose I meant that it could not depend on an "unrestricted" generic parameter (or "guaranteed well-formed"). Yes, it's quite difficult to use language that's both intuitive, and doesn't take up a lot of space. Linking to the issue would be good. 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. +1 on linking to that issue. I would say I've come around to the position that reducing verbosity is a goal, but much lower than correct understandable wording. 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. Opened #71142 for this subthread. |
||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
// check-pass | ||
|
||
#![allow(incomplete_features, dead_code, unconditional_recursion)] | ||
#![feature(const_generics)] | ||
|
||
fn fact<const N: usize>() { | ||
fact::<{ N - 1 }>(); | ||
//~^ ERROR constant expression depends on a generic parameter | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/issue-66205.rs:5:12 | ||
| | ||
LL | fact::<{ N - 1 }>(); | ||
| ^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/issue-67739.rs:12:15 | ||
| | ||
LL | [0u8; mem::size_of::<Self::Associated>()]; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
fn main() { | ||
[(); { &loop { break } as *const _ as usize } ]; | ||
//~^ ERROR `loop` is not allowed in a `const` | ||
//~| ERROR casting pointers to integers in constants is unstable | ||
//~| ERROR evaluation of constant value failed | ||
} |
Uh oh!
There was an error while loading. Please reload this page.