-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 #74487 - lcnr:const-in-ty-default, r=varkor
Forbid generic parameters in anon consts inside of type defaults Emit a resolution error for `struct Foo<T, U = [u8; std::mem::size_of::<T>()]>`. We are unable to support this with the way `ty::Generics` is currently used, so let's just forbid it entirely for now. Fixes some ICE on stable, e.g. ```rust struct Foo<T, U = [u8; std::mem::size_of::<*mut T>()]>(T, U); ``` r? @varkor @eddyb
- Loading branch information
Showing
7 changed files
with
135 additions
and
13 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
11 changes: 11 additions & 0 deletions
11
src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.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,11 @@ | ||
#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete | ||
|
||
struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U); | ||
//~^ ERROR constant values inside of type parameter defaults | ||
|
||
// FIXME(const_generics:defaults): We still don't know how to we deal with type defaults. | ||
struct Bar<T = [u8; N], const N: usize>(T); | ||
//~^ ERROR constant values inside of type parameter defaults | ||
//~| ERROR type parameters with a default | ||
|
||
fn main() {} |
31 changes: 31 additions & 0 deletions
31
src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.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,31 @@ | ||
error: type parameters with a default must be trailing | ||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:7:12 | ||
| | ||
LL | struct Bar<T = [u8; N], const N: usize>(T); | ||
| ^ | ||
| | ||
= note: using type defaults and const parameters in the same parameter list is currently not permitted | ||
|
||
error: constant values inside of type parameter defaults must not depend on generic parameters | ||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:3:44 | ||
| | ||
LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U); | ||
| ^ the anonymous constant must not depend on the parameter `T` | ||
|
||
error: constant values inside of type parameter defaults must not depend on generic parameters | ||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:7:21 | ||
| | ||
LL | struct Bar<T = [u8; N], const N: usize>(T); | ||
| ^ the anonymous constant must not depend on the parameter `N` | ||
|
||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:1:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
|
||
error: aborting due to 3 previous errors; 1 warning emitted | ||
|
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,4 @@ | ||
struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U); | ||
//~^ ERROR constant values inside of type parameter defaults | ||
|
||
fn main() {} |
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: constant values inside of type parameter defaults must not depend on generic parameters | ||
--> $DIR/param-in-ct-in-ty-param-default.rs:1:44 | ||
| | ||
LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U); | ||
| ^ the anonymous constant must not depend on the parameter `T` | ||
|
||
error: aborting due to previous error | ||
|