supply substs to anon consts in defaults

This commit is contained in:
lcnr 2021-04-18 16:43:43 +02:00
parent 312b4fdfd2
commit d3e0d2f53d
11 changed files with 62 additions and 71 deletions

View file

@ -1,16 +1,18 @@
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/complex-generic-default-expr.rs:9:62
error: constant expression depends on a generic parameter
--> $DIR/complex-generic-default-expr.rs:6:34
|
LL | struct Foo<const N: usize, const M: usize = { N + 1 }>;
| ^
|
= note: this may fail depending on what value the parameter takes
error: constant expression depends on a generic parameter
--> $DIR/complex-generic-default-expr.rs:10:21
|
LL | struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
| - ^ doesn't have a size known at compile-time
| |
| this type parameter needs to be `std::marker::Sized`
|
::: $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`
= note: this may fail depending on what value the parameter takes
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,5 +1,5 @@
error: generic parameters may not be used in const operations
--> $DIR/complex-generic-default-expr.rs:10:47
--> $DIR/complex-generic-default-expr.rs:6:47
|
LL | struct Foo<const N: usize, const M: usize = { N + 1 }>;
| ^ cannot perform const operation using `N`
@ -8,7 +8,7 @@ LL | struct Foo<const N: usize, const M: usize = { N + 1 }>;
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
error: generic parameters may not be used in const operations
--> $DIR/complex-generic-default-expr.rs:13:62
--> $DIR/complex-generic-default-expr.rs:10:62
|
LL | struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
| ^ cannot perform const operation using `T`

View file

@ -1,17 +1,14 @@
// revisions: min
// FIXME(const_generics): add the `full` revision,
// currently causes an ICE as we don't supply substs to
// anon consts in the parameter listing, as that would
// cause that anon const to reference itself.
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![feature(const_generics_defaults)]
#![allow(incomplete_features)]
struct Foo<const N: usize, const M: usize = { N + 1 }>;
//[min]~^ ERROR generic parameters may not be used in const operations
//[full]~^ ERROR constant expression depends on a generic parameter
//[min]~^^ ERROR generic parameters may not be used in const operations
struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
//[min]~^ ERROR generic parameters may not be used in const operations
//[full]~^^ ERROR the size for values of type `T` cannot be known at compilation time
//[full]~^ ERROR constant expression depends on a generic parameter
//[min]~^^ ERROR generic parameters may not be used in const operations
fn main() {}

View file

@ -8,7 +8,16 @@ fn foo<const N: usize>() -> Foo<N> {
Foo(x, x)
}
// To check that we actually apply the correct substs for const param defaults.
fn concrete_foo() -> Foo<13> {
Foo(Default::default(), Default::default())
}
fn main() {
let val = foo::<13>();
assert_eq!(val.0, val.1);
let val = concrete_foo();
assert_eq!(val.0, val.1);
}

View file

@ -1,10 +1,6 @@
// run-pass
#![feature(const_generics_defaults)]
#![allow(incomplete_features)]
// FIXME(const_generics_defaults): while we can allow this,
// we probably won't easily allow this with more complex const operations.
//
// So we have to make a conscious decision here when stabilizing a relaxed parameter ordering.
struct Foo<const N: usize, T = [u8; N]>(T);
impl<const N: usize> Foo<N> {

View file

@ -1,5 +1,5 @@
error: generic parameters with a default must be trailing
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:10:12
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:12
|
LL | struct Bar<T = [u8; N], const N: usize>(T);
| ^
@ -7,25 +7,11 @@ 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[E0128]: generic parameters with a default cannot use forward declared identifiers
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:10:21
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21
|
LL | struct Bar<T = [u8; N], const N: usize>(T);
| ^ defaulted generic parameters cannot be forward declared
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:6:44
|
LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
| - ^ doesn't have a size known at compile-time
| |
| this type parameter needs to be `std::marker::Sized`
|
::: $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: aborting due to 2 previous errors
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0128, E0277.
For more information about an error, try `rustc --explain E0128`.
For more information about this error, try `rustc --explain E0128`.

View file

@ -1,5 +1,5 @@
error: generic parameters with a default must be trailing
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:10:12
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:12
|
LL | struct Bar<T = [u8; N], const N: usize>(T);
| ^
@ -7,7 +7,7 @@ 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: generic parameters may not be used in const operations
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:6:44
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:5:44
|
LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
| ^ cannot perform const operation using `T`
@ -16,7 +16,7 @@ LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
error[E0128]: generic parameters with a default cannot use forward declared identifiers
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:10:21
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21
|
LL | struct Bar<T = [u8; N], const N: usize>(T);
| ^ defaulted generic parameters cannot be forward declared

View file

@ -1,11 +1,9 @@
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
//[full]~^ ERROR the size for values of type `T` cannot be known at compilation time
//[min]~^^ ERROR generic parameters may not be used in const operations
//[min]~^ ERROR generic parameters may not be used in const operations
struct Bar<T = [u8; N], const N: usize>(T);
//~^ ERROR generic parameters with a default cannot use forward declared identifiers