fix name resolution for param defaults
This commit is contained in:
parent
d7c3386414
commit
259a368e9e
15 changed files with 141 additions and 104 deletions
|
|
@ -0,0 +1,9 @@
|
|||
#![feature(const_generics, const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct Foo<const N: usize, const M: usize = { N + 1 }>;
|
||||
|
||||
struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
|
||||
//~^ ERROR the size for values of type `T` cannot be known at compilation time
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
error[E0277]: the size for values of type `T` cannot be known at compilation time
|
||||
--> $DIR/complex-generic-default-expr.rs:6:62
|
||||
|
|
||||
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`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
9
src/test/ui/const-generics/defaults/default-on-impl.rs
Normal file
9
src/test/ui/const-generics/defaults/default-on-impl.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#![feature(const_generics, const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct Foo<const N: usize>;
|
||||
|
||||
impl<const N: usize = 1> Foo<N> {}
|
||||
//~^ ERROR defaults for const parameters are only allowed
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
||||
--> $DIR/default-on-impl.rs:6:12
|
||||
|
|
||||
LL | impl<const N: usize = 1> Foo<N> {}
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -10,4 +10,5 @@ trait Foo<const KIND: bool = true> {}
|
|||
|
||||
fn foo<const SIZE: usize = 5>() {}
|
||||
|
||||
struct Range<const FROM: usize = 0, const LEN: usize = 0, const TO: usize = {FROM + LEN}>;
|
||||
struct Range<const FROM: usize = 0, const LEN: usize = 0, const TO: usize = FROM>;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ trait Foo<const KIND : bool = true> { }
|
|||
fn foo<const SIZE : usize = 5>() { }
|
||||
|
||||
struct Range<const FROM : usize = 0, const LEN : usize = 0, const TO : usize =
|
||||
{ FROM + LEN }>;
|
||||
FROM>;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
// check-pass
|
||||
#![feature(const_generics, const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct N;
|
||||
|
||||
struct Foo<const N: usize = 1, T = N>(T);
|
||||
|
||||
impl Foo {
|
||||
fn new() -> Self {
|
||||
Foo(N)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let Foo::<1, N>(N) = Foo::new();
|
||||
}
|
||||
|
|
@ -6,17 +6,26 @@ 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:6: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
|
||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:11:21
|
||||
|
|
||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||
| ^ the anonymous constant must not depend on the parameter `N`
|
||||
| ^ 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 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0128, E0277.
|
||||
For more information about an error, try `rustc --explain E0128`.
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@ LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
|
|||
= note: type parameters may not be used in const expressions
|
||||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error: constant values inside of type parameter defaults must not depend on generic parameters
|
||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:11:21
|
||||
|
|
||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||
| ^ the anonymous constant must not depend on the parameter `N`
|
||||
| ^ defaulted generic parameters cannot be forward declared
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0128`.
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
|
||||
struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
|
||||
//[full]~^ ERROR constant values inside of type parameter defaults
|
||||
//[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
|
||||
|
||||
// FIXME(const_generics_defaults): We still don't know how to deal with type defaults.
|
||||
struct Bar<T = [u8; N], const N: usize>(T);
|
||||
//~^ ERROR constant values inside of type parameter defaults
|
||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
||||
//~| ERROR generic parameters with a default
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ struct Vec<A = Heap, T>(A, T);
|
|||
|
||||
struct Foo<A, B = Vec<C>, C>(A, B, C);
|
||||
//~^ ERROR generic parameters with a default must be trailing
|
||||
//~| ERROR generic parameters with a default cannot use
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,12 @@ error: generic parameters with a default must be trailing
|
|||
LL | struct Foo<A, B = Vec<C>, C>(A, B, C);
|
||||
| ^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
||||
--> $DIR/generic-non-trailing-defaults.rs:6:23
|
||||
|
|
||||
LL | struct Foo<A, B = Vec<C>, C>(A, B, C);
|
||||
| ^ defaulted generic parameters cannot be forward declared
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0128`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue