-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Fix missing diagnostic span for impl Trait
with const generics, and add various tests for min_const_generics
and const_generics
#77439
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
Merged
+628
−66
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0801263
Fix missing diagnostic span for `impl Trait` with const generics
varkor 1db05e0
Add various `min_const_generics` regression tests
varkor 488b759
Replace "non trivial" with "non-trivial"
varkor 96eb68b
Add `FIXME` for const generic defaults
varkor 3631d29
Add tests for `const_generics`
varkor 7029065
Move tests
varkor 6647eee
Add `const_generics` test for `impl-trait-with-const-arguments`
varkor 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
Add tests for
const_generics
- Loading branch information
commit 3631d2928764c0c321c60cbbe1bdd6ab5945d452
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/test/ui/const-generics/min_const_generics/const-argument-if-length.full.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,42 @@ | ||
error[E0277]: the size for values of type `T` cannot be known at compilation time | ||
--> $DIR/const-argument-if-length.rs:8:28 | ||
| | ||
LL | pub const fn is_zst<T: ?Sized>() -> usize { | ||
| - this type parameter needs to be `Sized` | ||
LL | if std::mem::size_of::<T>() == 0 { | ||
| ^ doesn't have a size known at compile-time | ||
| | ||
::: $SRC_DIR/core/src/mem/mod.rs:LL:COL | ||
| | ||
LL | pub const fn size_of<T>() -> usize { | ||
| - required by this bound in `std::mem::size_of` | ||
|
||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/const-argument-if-length.rs:19:15 | ||
| | ||
LL | pad: [u8; is_zst::<T>()], | ||
| ^^^^^^^^^^^^^ referenced constant has errors | ||
|
||
error[E0277]: the size for values of type `T` cannot be known at compilation time | ||
--> $DIR/const-argument-if-length.rs:17:12 | ||
| | ||
LL | pub struct AtLeastByte<T: ?Sized> { | ||
| - this type parameter needs to be `Sized` | ||
LL | value: T, | ||
| ^ doesn't have a size known at compile-time | ||
| | ||
= note: only the last field of a struct may have a dynamically sized type | ||
= help: change the field's type to have a statically known size | ||
help: borrowed types always have a statically known size | ||
| | ||
LL | value: &T, | ||
| ^ | ||
help: the `Box` type always has a statically known size and allocates its contents in the heap | ||
| | ||
LL | value: Box<T>, | ||
| ^^^^ ^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0080, E0277. | ||
For more information about an error, try `rustc --explain E0080`. |
30 changes: 30 additions & 0 deletions
30
src/test/ui/const-generics/min_const_generics/const-argument-if-length.min.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,30 @@ | ||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/const-argument-if-length.rs:19:24 | ||
| | ||
LL | pad: [u8; is_zst::<T>()], | ||
| ^ non-trivial anonymous constants must not depend on the parameter `T` | ||
| | ||
= note: type parameters are currently not permitted in anonymous constants | ||
|
||
error[E0277]: the size for values of type `T` cannot be known at compilation time | ||
--> $DIR/const-argument-if-length.rs:17:12 | ||
| | ||
LL | pub struct AtLeastByte<T: ?Sized> { | ||
| - this type parameter needs to be `Sized` | ||
LL | value: T, | ||
| ^ doesn't have a size known at compile-time | ||
| | ||
= note: only the last field of a struct may have a dynamically sized type | ||
= help: change the field's type to have a statically known size | ||
help: borrowed types always have a statically known size | ||
| | ||
LL | value: &T, | ||
| ^ | ||
help: the `Box` type always has a statically known size and allocates its contents in the heap | ||
| | ||
LL | value: Box<T>, | ||
| ^^^^ ^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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
10 changes: 10 additions & 0 deletions
10
...st/ui/const-generics/min_const_generics/generic-function-call-in-array-length.full.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,10 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/generic-function-call-in-array-length.rs:9:29 | ||
| | ||
LL | fn bar<const N: usize>() -> [u32; foo(N)] { | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
18 changes: 18 additions & 0 deletions
18
...est/ui/const-generics/min_const_generics/generic-function-call-in-array-length.min.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,18 @@ | ||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/generic-function-call-in-array-length.rs:9:39 | ||
| | ||
LL | fn bar<const N: usize>() -> [u32; foo(N)] { | ||
| ^ non-trivial anonymous constants must not depend on the parameter `N` | ||
| | ||
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants | ||
|
||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/generic-function-call-in-array-length.rs:12:13 | ||
| | ||
LL | [0; foo(N)] | ||
| ^ non-trivial anonymous constants must not depend on the parameter `N` | ||
| | ||
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants | ||
|
||
error: aborting due to 2 previous errors | ||
|
11 changes: 8 additions & 3 deletions
11
src/test/ui/const-generics/min_const_generics/generic-function-call-in-array-length.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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
#![feature(min_const_generics)] | ||
// revisions: full min | ||
|
||
#![cfg_attr(full, allow(incomplete_features))] | ||
#![cfg_attr(full, feature(const_generics))] | ||
#![cfg_attr(min, feature(min_const_generics))] | ||
|
||
const fn foo(n: usize) -> usize { n * 2 } | ||
|
||
fn bar<const N: usize>() -> [u32; foo(N)] { | ||
//~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[full]~^^ ERROR constant expression depends on a generic parameter | ||
[0; foo(N)] | ||
//~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
} | ||
|
||
fn main() {} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.full.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,10 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/generic-sum-in-array-length.rs:7:45 | ||
| | ||
LL | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {} | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
18 changes: 18 additions & 0 deletions
18
src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.min.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,18 @@ | ||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/generic-sum-in-array-length.rs:7:53 | ||
| | ||
LL | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {} | ||
| ^ non-trivial anonymous constants must not depend on the parameter `A` | ||
| | ||
= help: it is currently only allowed to use either `A` or `{ A }` as generic constants | ||
|
||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/generic-sum-in-array-length.rs:7:57 | ||
| | ||
LL | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {} | ||
| ^ non-trivial anonymous constants must not depend on the parameter `B` | ||
| | ||
= help: it is currently only allowed to use either `B` or `{ B }` as generic constants | ||
|
||
error: aborting due to 2 previous errors | ||
|
11 changes: 8 additions & 3 deletions
11
src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
#![feature(min_const_generics)] | ||
// revisions: full min | ||
|
||
#![cfg_attr(full, allow(incomplete_features))] | ||
#![cfg_attr(full, feature(const_generics))] | ||
#![cfg_attr(min, feature(min_const_generics))] | ||
|
||
fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {} | ||
//~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
//~| ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[min]~| ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[full]~^^^ ERROR constant expression depends on a generic parameter | ||
|
||
fn main() {} |
10 changes: 10 additions & 0 deletions
10
...t/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.full.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,10 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/intrinsics-type_name-as-const-argument.rs:15:8 | ||
| | ||
LL | T: Trait<{std::intrinsics::type_name::<T>()}> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
19 changes: 19 additions & 0 deletions
19
...st/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.min.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,19 @@ | ||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/intrinsics-type_name-as-const-argument.rs:15:44 | ||
| | ||
LL | T: Trait<{std::intrinsics::type_name::<T>()}> | ||
| ^ non-trivial anonymous constants must not depend on the parameter `T` | ||
| | ||
= note: type parameters are currently not permitted in anonymous constants | ||
|
||
error: `&'static str` is forbidden as the type of a const generic parameter | ||
--> $DIR/intrinsics-type_name-as-const-argument.rs:10:22 | ||
| | ||
LL | trait Trait<const S: &'static str> {} | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
= note: more complex types are supported with `#[feature(const_generics)]` | ||
|
||
error: aborting due to 2 previous errors | ||
|
13 changes: 10 additions & 3 deletions
13
src/test/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.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
21 changes: 21 additions & 0 deletions
21
src/test/ui/const-generics/min_const_generics/issue-67375.full.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,21 @@ | ||
warning: cannot use constants which depend on generic parameters in types | ||
--> $DIR/issue-67375.rs:9:12 | ||
| | ||
LL | inner: [(); { [|_: &T| {}; 0].len() }], | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(const_evaluatable_unchecked)]` on by default | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200> | ||
|
||
error[E0392]: parameter `T` is never used | ||
--> $DIR/issue-67375.rs:7:12 | ||
| | ||
LL | struct Bug<T> { | ||
| ^ unused parameter | ||
| | ||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0392`. |
19 changes: 19 additions & 0 deletions
19
src/test/ui/const-generics/min_const_generics/issue-67375.min.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,19 @@ | ||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/issue-67375.rs:9:25 | ||
| | ||
LL | inner: [(); { [|_: &T| {}; 0].len() }], | ||
| ^ non-trivial anonymous constants must not depend on the parameter `T` | ||
| | ||
= note: type parameters are currently not permitted in anonymous constants | ||
|
||
error[E0392]: parameter `T` is never used | ||
--> $DIR/issue-67375.rs:7:12 | ||
| | ||
LL | struct Bug<T> { | ||
| ^ unused parameter | ||
| | ||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0392`. |
10 changes: 8 additions & 2 deletions
10
src/test/ui/const-generics/min_const_generics/issue-67375.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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
#![feature(min_const_generics)] | ||
// revisions: full min | ||
|
||
#![cfg_attr(full, allow(incomplete_features))] | ||
#![cfg_attr(full, feature(const_generics))] | ||
#![cfg_attr(min, feature(min_const_generics))] | ||
|
||
struct Bug<T> { | ||
//~^ ERROR parameter `T` is never used | ||
inner: [(); { [|_: &T| {}; 0].len() }], | ||
//~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[full]~^^ WARN cannot use constants which depend on generic parameters in types | ||
//[full]~^^^ WARN this was previously accepted by the compiler | ||
} | ||
|
||
fn main() {} |
26 changes: 26 additions & 0 deletions
26
src/test/ui/const-generics/min_const_generics/issue-67945-1.full.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,26 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-67945-1.rs:14:20 | ||
| | ||
LL | struct Bug<S> { | ||
| - this type parameter | ||
... | ||
LL | let x: S = MaybeUninit::uninit(); | ||
| - ^^^^^^^^^^^^^^^^^^^^^ expected type parameter `S`, found union `MaybeUninit` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type parameter `S` | ||
found union `MaybeUninit<_>` | ||
|
||
error[E0392]: parameter `S` is never used | ||
--> $DIR/issue-67945-1.rs:11:12 | ||
| | ||
LL | struct Bug<S> { | ||
| ^ unused parameter | ||
| | ||
= help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0392. | ||
For more information about an error, try `rustc --explain E0308`. |
27 changes: 27 additions & 0 deletions
27
src/test/ui/const-generics/min_const_generics/issue-67945-1.min.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,27 @@ | ||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/issue-67945-1.rs:14:16 | ||
| | ||
LL | let x: S = MaybeUninit::uninit(); | ||
| ^ non-trivial anonymous constants must not depend on the parameter `S` | ||
| | ||
= note: type parameters are currently not permitted in anonymous constants | ||
|
||
error: generic parameters must not be used inside of non-trivial constant values | ||
--> $DIR/issue-67945-1.rs:17:45 | ||
| | ||
LL | let b = &*(&x as *const _ as *const S); | ||
| ^ non-trivial anonymous constants must not depend on the parameter `S` | ||
| | ||
= note: type parameters are currently not permitted in anonymous constants | ||
|
||
error[E0392]: parameter `S` is never used | ||
--> $DIR/issue-67945-1.rs:11:12 | ||
| | ||
LL | struct Bug<S> { | ||
| ^ unused parameter | ||
| | ||
= help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0392`. |
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.
Uh oh!
There was an error while loading. Please reload this page.