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
This commit is contained in:
commit
e0543409d5
7 changed files with 135 additions and 13 deletions
|
|
@ -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() {}
|
||||
|
|
@ -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
|
||||
|
||||
4
src/test/ui/generic/param-in-ct-in-ty-param-default.rs
Normal file
4
src/test/ui/generic/param-in-ct-in-ty-param-default.rs
Normal file
|
|
@ -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() {}
|
||||
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue