forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#77439 - varkor:min_const_generics-tests, r=…
…lcnr,estebank Fix missing diagnostic span for `impl Trait` with const generics, and add various tests for `min_const_generics` and `const_generics` Closes rust-lang#61410. Adds `min_const_generics` tests for: - rust-lang#73727 - rust-lang#72293 - rust-lang#67375 - rust-lang#75153 - rust-lang#71922 - rust-lang#69913 - rust-lang#67945 - rust-lang#69239 Adds `const_generics` tests for: - rust-lang#67375 - rust-lang#75153 - rust-lang#71922 - rust-lang#69913 - rust-lang#67945 - rust-lang#69239 (I only added separate `min_const_generics` and `const_generics` tests if they were handled differently by the two features.) We need to figure out how to deduplicate when `const_generics` is stabilised, but we can discuss that later. For now, we should be checking neither feature breaks, so require regression tests for both. I've given them identical names when I've added both, which should make it easier to spot them later. r? @lcnr
- Loading branch information
Showing
74 changed files
with
628 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
4 changes: 2 additions & 2 deletions
4
src/test/ui/const-generics/array-size-in-generic-struct-param.min.stderr
This file contains 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 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
42 changes: 42 additions & 0 deletions
42
src/test/ui/const-generics/const-argument-if-length.full.stderr
This file contains 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/const-argument-if-length.min.stderr
This file contains 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 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 @@ | ||
// revisions: full min | ||
|
||
#![cfg_attr(full, allow(incomplete_features))] | ||
#![cfg_attr(full, feature(const_generics))] | ||
#![cfg_attr(min, feature(min_const_generics))] | ||
|
||
pub const fn is_zst<T: ?Sized>() -> usize { | ||
if std::mem::size_of::<T>() == 0 { | ||
//[full]~^ ERROR the size for values of type `T` cannot be known at compilation time | ||
1 | ||
} else { | ||
0 | ||
} | ||
} | ||
|
||
pub struct AtLeastByte<T: ?Sized> { | ||
value: T, | ||
//~^ ERROR the size for values of type `T` cannot be known at compilation time | ||
pad: [u8; is_zst::<T>()], | ||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values | ||
//[full]~^^ ERROR evaluation of constant value failed | ||
} | ||
|
||
fn main() {} |
2 changes: 1 addition & 1 deletion
2
...onst-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.min.stderr
This file contains 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 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
4 changes: 2 additions & 2 deletions
4
src/test/ui/const-generics/const_evaluatable_checked/simple.min.stderr
This file contains 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
2 changes: 1 addition & 1 deletion
2
src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr
This file contains 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 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
src/test/ui/const-generics/generic-function-call-in-array-length.full.stderr
This file contains 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
src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr
This file contains 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 | ||
|
16 changes: 16 additions & 0 deletions
16
src/test/ui/const-generics/generic-function-call-in-array-length.rs
This file contains 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,16 @@ | ||
// 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)] { | ||
//[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)] | ||
//[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/generic-sum-in-array-length.full.stderr
This file contains 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/generic-sum-in-array-length.min.stderr
This file contains 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 | ||
|
This file contains 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 @@ | ||
// 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]) {} | ||
//[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() {} |
8 changes: 8 additions & 0 deletions
8
src/test/ui/const-generics/impl-trait-with-const-arguments.full.stderr
This file contains 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,8 @@ | ||
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position | ||
--> $DIR/impl-trait-with-const-arguments.rs:24:20 | ||
| | ||
LL | assert_eq!(f::<4usize>(Usizable), 20usize); | ||
| ^^^^^^ explicit generic argument not allowed | ||
|
||
error: aborting due to previous error | ||
|
8 changes: 8 additions & 0 deletions
8
src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr
This file contains 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,8 @@ | ||
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position | ||
--> $DIR/impl-trait-with-const-arguments.rs:24:20 | ||
| | ||
LL | assert_eq!(f::<4usize>(Usizable), 20usize); | ||
| ^^^^^^ explicit generic argument not allowed | ||
|
||
error: aborting due to previous error | ||
|
26 changes: 26 additions & 0 deletions
26
src/test/ui/const-generics/impl-trait-with-const-arguments.rs
This file contains 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 @@ | ||
// revisions: full min | ||
|
||
#![cfg_attr(full, allow(incomplete_features))] | ||
#![cfg_attr(full, feature(const_generics))] | ||
#![cfg_attr(min, feature(min_const_generics))] | ||
|
||
trait Usizer { | ||
fn m(self) -> usize; | ||
} | ||
|
||
fn f<const N: usize>(u: impl Usizer) -> usize { | ||
N + u.m() | ||
} | ||
|
||
struct Usizable; | ||
|
||
impl Usizer for Usizable { | ||
fn m(self) -> usize { | ||
16 | ||
} | ||
} | ||
|
||
fn main() { | ||
assert_eq!(f::<4usize>(Usizable), 20usize); | ||
//~^ ERROR cannot provide explicit generic arguments when `impl Trait` is used in argument position | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/const-generics/intrinsics-type_name-as-const-argument.full.stderr
This file contains 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
src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr
This file contains 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 | ||
|
Oops, something went wrong.