mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 22:46:50 +00:00
Rollup merge of #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 https://github.com/rust-lang/rust/issues/61410. Adds `min_const_generics` tests for: - https://github.com/rust-lang/rust/issues/73727 - https://github.com/rust-lang/rust/issues/72293 - https://github.com/rust-lang/rust/issues/67375 - https://github.com/rust-lang/rust/issues/75153 - https://github.com/rust-lang/rust/issues/71922 - https://github.com/rust-lang/rust/issues/69913 - https://github.com/rust-lang/rust/issues/67945 - https://github.com/rust-lang/rust/issues/69239 Adds `const_generics` tests for: - https://github.com/rust-lang/rust/issues/67375 - https://github.com/rust-lang/rust/issues/75153 - https://github.com/rust-lang/rust/issues/71922 - https://github.com/rust-lang/rust/issues/69913 - https://github.com/rust-lang/rust/issues/67945 - https://github.com/rust-lang/rust/issues/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
This commit is contained in:
commit
e032bb7c65
@ -581,7 +581,7 @@ declare_features! (
|
||||
/// Allows `if let` guard in match arms.
|
||||
(active, if_let_guard, "1.47.0", Some(51114), None),
|
||||
|
||||
/// Allows non trivial generic constants which have to be manually propageted upwards.
|
||||
/// Allows non-trivial generic constants which have to be manually propageted upwards.
|
||||
(active, const_evaluatable_checked, "1.48.0", Some(76560), None),
|
||||
|
||||
/// Allows basic arithmetic on floating point types in a `const fn`.
|
||||
|
@ -469,7 +469,7 @@ impl<'a> Resolver<'a> {
|
||||
ResolutionError::ParamInNonTrivialAnonConst { name, is_type } => {
|
||||
let mut err = self.session.struct_span_err(
|
||||
span,
|
||||
"generic parameters must not be used inside of non trivial constant values",
|
||||
"generic parameters must not be used inside of non-trivial constant values",
|
||||
);
|
||||
err.span_label(
|
||||
span,
|
||||
|
@ -218,7 +218,7 @@ enum ResolutionError<'a> {
|
||||
ParamInTyOfConstParam(Symbol),
|
||||
/// constant values inside of type parameter defaults must not depend on generic parameters.
|
||||
ParamInAnonConstInTyDefault(Symbol),
|
||||
/// generic parameters must not be used inside of non trivial constant values.
|
||||
/// generic parameters must not be used inside of non-trivial constant values.
|
||||
///
|
||||
/// This error is only emitted when using `min_const_generics`.
|
||||
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },
|
||||
|
@ -562,7 +562,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
.args
|
||||
.iter()
|
||||
.filter_map(|arg| match arg {
|
||||
GenericArg::Type(_) => Some(arg.span()),
|
||||
GenericArg::Type(_) | GenericArg::Const(_) => Some(arg.span()),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -222,6 +222,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
||||
hir::GenericParamKind::Const { .. } => {
|
||||
let def_id = self.tcx.hir().local_def_id(param.hir_id);
|
||||
self.tcx.ensure().type_of(def_id);
|
||||
// FIXME(const_generics:defaults)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:9:48
|
||||
|
|
||||
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
|
||||
@ -6,7 +6,7 @@ LL | struct ArithArrayLen<const N: usize>([u32; 0 + 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
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:20:15
|
||||
|
|
||||
LL | arr: [u8; CFG.arr_size],
|
||||
|
@ -8,7 +8,7 @@
|
||||
#[allow(dead_code)]
|
||||
struct ArithArrayLen<const N: usize>([u32; 0 + N]);
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
struct Config {
|
||||
@ -19,7 +19,7 @@ struct B<const CFG: Config> {
|
||||
//[min]~^ ERROR `Config` is forbidden
|
||||
arr: [u8; CFG.arr_size],
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non trivial
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non-trivial
|
||||
}
|
||||
|
||||
const C: Config = Config { arr_size: 5 };
|
||||
|
@ -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`.
|
@ -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`.
|
24
src/test/ui/const-generics/const-argument-if-length.rs
Normal file
24
src/test/ui/const-generics/const-argument-if-length.rs
Normal file
@ -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() {}
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/feature-gate-const_evaluatable_checked.rs:6:33
|
||||
|
|
||||
LL | type Arr<const N: usize> = [u8; N - 1];
|
||||
|
@ -4,7 +4,7 @@
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
type Arr<const N: usize> = [u8; N - 1];
|
||||
//[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
|
||||
|
||||
fn test<const N: usize>() -> Arr<N> where Arr<N>: Default {
|
||||
//[full]~^ ERROR constant expression depends
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/simple.rs:8:53
|
||||
|
|
||||
LL | fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
|
||||
@ -6,7 +6,7 @@ LL | fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
|
||||
|
|
||||
= 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
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/simple.rs:8:35
|
||||
|
|
||||
LL | fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/simple_fail.rs:7:33
|
||||
|
|
||||
LL | type Arr<const N: usize> = [u8; N - 1];
|
||||
|
@ -5,7 +5,7 @@
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
type Arr<const N: usize> = [u8; N - 1]; //[full]~ ERROR evaluation of constant
|
||||
//[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
|
||||
|
||||
fn test<const N: usize>() -> Arr<N> where Arr<N>: Sized {
|
||||
todo!()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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() {}
|
@ -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
|
||||
|
@ -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
|
||||
|
12
src/test/ui/const-generics/generic-sum-in-array-length.rs
Normal file
12
src/test/ui/const-generics/generic-sum-in-array-length.rs
Normal file
@ -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() {}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,22 @@
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_type_name)]
|
||||
|
||||
trait Trait<const S: &'static str> {}
|
||||
//[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter
|
||||
|
||||
struct Bug<T>
|
||||
where
|
||||
T: Trait<{std::intrinsics::type_name::<T>()}>
|
||||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
//[full]~^^ ERROR constant expression depends on a generic parameter
|
||||
{
|
||||
t: T
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-61522-array-len-succ.rs:7:45
|
||||
|
|
||||
LL | pub struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
|
||||
@ -6,7 +6,7 @@ LL | pub struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
|
||||
|
|
||||
= help: it is currently only allowed to use either `COUNT` or `{ COUNT }` as generic constants
|
||||
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-61522-array-len-succ.rs:12:30
|
||||
|
|
||||
LL | fn inner(&self) -> &[u8; COUNT + 1] {
|
||||
|
21
src/test/ui/const-generics/issue-67375.full.stderr
Normal file
21
src/test/ui/const-generics/issue-67375.full.stderr
Normal file
@ -0,0 +1,21 @@
|
||||
warning: cannot use constants which depend on generic parameters in types
|
||||
--> $DIR/issue-67375.rs:9:12
|
||||
|
|
||||
LL | inner: [(); { [|_: &T| {}; 0].len() }],
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(const_evaluatable_unchecked)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
|
||||
|
||||
error[E0392]: parameter `T` is never used
|
||||
--> $DIR/issue-67375.rs:7:12
|
||||
|
|
||||
LL | struct Bug<T> {
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0392`.
|
19
src/test/ui/const-generics/issue-67375.min.stderr
Normal file
19
src/test/ui/const-generics/issue-67375.min.stderr
Normal file
@ -0,0 +1,19 @@
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-67375.rs:9:25
|
||||
|
|
||||
LL | inner: [(); { [|_: &T| {}; 0].len() }],
|
||||
| ^ non-trivial anonymous constants must not depend on the parameter `T`
|
||||
|
|
||||
= note: type parameters are currently not permitted in anonymous constants
|
||||
|
||||
error[E0392]: parameter `T` is never used
|
||||
--> $DIR/issue-67375.rs:7:12
|
||||
|
|
||||
LL | struct Bug<T> {
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0392`.
|
15
src/test/ui/const-generics/issue-67375.rs
Normal file
15
src/test/ui/const-generics/issue-67375.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct Bug<T> {
|
||||
//~^ ERROR parameter `T` is never used
|
||||
inner: [(); { [|_: &T| {}; 0].len() }],
|
||||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
//[full]~^^ WARN cannot use constants which depend on generic parameters in types
|
||||
//[full]~^^^ WARN this was previously accepted by the compiler
|
||||
}
|
||||
|
||||
fn main() {}
|
26
src/test/ui/const-generics/issue-67945-1.full.stderr
Normal file
26
src/test/ui/const-generics/issue-67945-1.full.stderr
Normal file
@ -0,0 +1,26 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-67945-1.rs:14:20
|
||||
|
|
||||
LL | struct Bug<S> {
|
||||
| - this type parameter
|
||||
...
|
||||
LL | let x: S = MaybeUninit::uninit();
|
||||
| - ^^^^^^^^^^^^^^^^^^^^^ expected type parameter `S`, found union `MaybeUninit`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected type parameter `S`
|
||||
found union `MaybeUninit<_>`
|
||||
|
||||
error[E0392]: parameter `S` is never used
|
||||
--> $DIR/issue-67945-1.rs:11:12
|
||||
|
|
||||
LL | struct Bug<S> {
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0392.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
27
src/test/ui/const-generics/issue-67945-1.min.stderr
Normal file
27
src/test/ui/const-generics/issue-67945-1.min.stderr
Normal file
@ -0,0 +1,27 @@
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-67945-1.rs:14:16
|
||||
|
|
||||
LL | let x: S = MaybeUninit::uninit();
|
||||
| ^ non-trivial anonymous constants must not depend on the parameter `S`
|
||||
|
|
||||
= note: type parameters are currently not permitted in anonymous constants
|
||||
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-67945-1.rs:17:45
|
||||
|
|
||||
LL | let b = &*(&x as *const _ as *const S);
|
||||
| ^ non-trivial anonymous constants must not depend on the parameter `S`
|
||||
|
|
||||
= note: type parameters are currently not permitted in anonymous constants
|
||||
|
||||
error[E0392]: parameter `S` is never used
|
||||
--> $DIR/issue-67945-1.rs:11:12
|
||||
|
|
||||
LL | struct Bug<S> {
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0392`.
|
23
src/test/ui/const-generics/issue-67945-1.rs
Normal file
23
src/test/ui/const-generics/issue-67945-1.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use std::mem::{self, MaybeUninit};
|
||||
|
||||
struct Bug<S> {
|
||||
//~^ ERROR parameter `S` is never used
|
||||
A: [(); {
|
||||
let x: S = MaybeUninit::uninit();
|
||||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
//[full]~^^ ERROR mismatched types
|
||||
let b = &*(&x as *const _ as *const S);
|
||||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
0
|
||||
}],
|
||||
}
|
||||
|
||||
fn main() {}
|
26
src/test/ui/const-generics/issue-67945-2.full.stderr
Normal file
26
src/test/ui/const-generics/issue-67945-2.full.stderr
Normal file
@ -0,0 +1,26 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-67945-2.rs:12:20
|
||||
|
|
||||
LL | struct Bug<S> {
|
||||
| - this type parameter
|
||||
...
|
||||
LL | let x: S = MaybeUninit::uninit();
|
||||
| - ^^^^^^^^^^^^^^^^^^^^^ expected type parameter `S`, found union `MaybeUninit`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected type parameter `S`
|
||||
found union `MaybeUninit<_>`
|
||||
|
||||
error[E0392]: parameter `S` is never used
|
||||
--> $DIR/issue-67945-2.rs:9:12
|
||||
|
|
||||
LL | struct Bug<S> {
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0392.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
27
src/test/ui/const-generics/issue-67945-2.min.stderr
Normal file
27
src/test/ui/const-generics/issue-67945-2.min.stderr
Normal file
@ -0,0 +1,27 @@
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-67945-2.rs:12:16
|
||||
|
|
||||
LL | let x: S = MaybeUninit::uninit();
|
||||
| ^ non-trivial anonymous constants must not depend on the parameter `S`
|
||||
|
|
||||
= note: type parameters are currently not permitted in anonymous constants
|
||||
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-67945-2.rs:15:45
|
||||
|
|
||||
LL | let b = &*(&x as *const _ as *const S);
|
||||
| ^ non-trivial anonymous constants must not depend on the parameter `S`
|
||||
|
|
||||
= note: type parameters are currently not permitted in anonymous constants
|
||||
|
||||
error[E0392]: parameter `S` is never used
|
||||
--> $DIR/issue-67945-2.rs:9:12
|
||||
|
|
||||
LL | struct Bug<S> {
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0392`.
|
21
src/test/ui/const-generics/issue-67945-2.rs
Normal file
21
src/test/ui/const-generics/issue-67945-2.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
struct Bug<S> {
|
||||
//~^ ERROR parameter `S` is never used
|
||||
A: [(); {
|
||||
let x: S = MaybeUninit::uninit();
|
||||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
//[full]~^^ ERROR mismatched types
|
||||
let b = &*(&x as *const _ as *const S);
|
||||
//[min]~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
0
|
||||
}],
|
||||
}
|
||||
|
||||
fn main() {}
|
16
src/test/ui/const-generics/issue-67945-3.full.stderr
Normal file
16
src/test/ui/const-generics/issue-67945-3.full.stderr
Normal file
@ -0,0 +1,16 @@
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-67945-3.rs:8:8
|
||||
|
|
||||
LL | A: [(); {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | | let x: Option<Box<Self>> = None;
|
||||
LL | |
|
||||
LL | | 0
|
||||
LL | | }],
|
||||
| |______^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to previous error
|
||||
|
8
src/test/ui/const-generics/issue-67945-3.min.stderr
Normal file
8
src/test/ui/const-generics/issue-67945-3.min.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error: generic `Self` types are currently not permitted in anonymous constants
|
||||
--> $DIR/issue-67945-3.rs:10:27
|
||||
|
|
||||
LL | let x: Option<Box<Self>> = None;
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
17
src/test/ui/const-generics/issue-67945-3.rs
Normal file
17
src/test/ui/const-generics/issue-67945-3.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct Bug<S: ?Sized> {
|
||||
A: [(); {
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
let x: Option<Box<Self>> = None;
|
||||
//[min]~^ ERROR generic `Self` types are currently not permitted in anonymous constants
|
||||
0
|
||||
}],
|
||||
B: S
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-61747.rs:8:30
|
||||
|
|
||||
LL | fn successor() -> Const<{C + 1}> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-61935.rs:10:23
|
||||
|
|
||||
LL | Self:FooImpl<{N==0}>
|
||||
|
@ -9,7 +9,7 @@ impl<const N: usize> Foo for [(); N]
|
||||
where
|
||||
Self:FooImpl<{N==0}>
|
||||
//[full]~^ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
{}
|
||||
|
||||
trait FooImpl<const IS_ZERO: bool>{}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-62220.rs:8:59
|
||||
|
|
||||
LL | pub type TruncatedVector<T, const N: usize> = Vector<T, { N - 1 }>;
|
||||
|
@ -6,7 +6,7 @@
|
||||
pub struct Vector<T, const N: usize>([T; N]);
|
||||
|
||||
pub type TruncatedVector<T, const N: usize> = Vector<T, { N - 1 }>;
|
||||
//[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
|
||||
|
||||
impl<T, const N: usize> Vector<T, { N }> {
|
||||
/// Drop the last component and return the vector with one fewer dimension.
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-62456.rs:7:20
|
||||
|
|
||||
LL | let _ = [0u64; N + 1];
|
||||
|
@ -6,7 +6,7 @@
|
||||
fn foo<const N: usize>() {
|
||||
let _ = [0u64; N + 1];
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-64494.rs:16:38
|
||||
|
|
||||
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 5}>: True {}
|
||||
@ -6,7 +6,7 @@ LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 5}>: True {}
|
||||
|
|
||||
= note: type parameters are currently not permitted in anonymous constants
|
||||
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-64494.rs:19:38
|
||||
|
|
||||
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 6}>: True {}
|
||||
|
@ -15,10 +15,10 @@ impl True for Is<{true}> {}
|
||||
|
||||
impl<T: Foo> MyTrait for T where Is<{T::VAL == 5}>: True {}
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
impl<T: Foo> MyTrait for T where Is<{T::VAL == 6}>: True {}
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
//[min]~| ERROR conflicting implementations of trait `MyTrait`
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-66205.rs:8:14
|
||||
|
|
||||
LL | fact::<{ N - 1 }>();
|
||||
|
@ -7,7 +7,7 @@
|
||||
fn fact<const N: usize>() {
|
||||
fact::<{ N - 1 }>();
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-67739.rs:12:30
|
||||
|
|
||||
LL | [0u8; mem::size_of::<Self::Associated>()];
|
||||
|
@ -11,7 +11,7 @@ pub trait Trait {
|
||||
fn associated_size(&self) -> usize {
|
||||
[0u8; mem::size_of::<Self::Associated>()];
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
0
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-68366.rs:12:37
|
||||
|
|
||||
LL | impl <const N: usize> Collatz<{Some(N)}> {}
|
||||
|
@ -11,7 +11,7 @@ struct Collatz<const N: Option<usize>>;
|
||||
|
||||
impl <const N: usize> Collatz<{Some(N)}> {}
|
||||
//~^ ERROR the const parameter
|
||||
//[min]~^^ generic parameters must not be used inside of non trivial constant values
|
||||
//[min]~^^ generic parameters must not be used inside of non-trivial constant values
|
||||
|
||||
struct Foo;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-68977.rs:29:17
|
||||
|
|
||||
LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
|
||||
@ -6,7 +6,7 @@ LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
|
||||
|
|
||||
= help: it is currently only allowed to use either `INT_BITS` or `{ INT_BITS }` as generic constants
|
||||
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-68977.rs:29:28
|
||||
|
|
||||
LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
|
||||
|
@ -27,8 +27,8 @@ fxp_storage_impls! {
|
||||
|
||||
type FxpStorageHelper<const INT_BITS: u8, const FRAC_BITS: u8> =
|
||||
PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
|
||||
//[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
|
||||
//[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
|
||||
|
||||
struct Fxp<const INT_BITS: u8, const FRAC_BITS: u8>
|
||||
where
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-72787.rs:11:17
|
||||
|
|
||||
LL | Condition<{ LHS <= RHS }>: True
|
||||
@ -6,7 +6,7 @@ LL | Condition<{ LHS <= RHS }>: True
|
||||
|
|
||||
= help: it is currently only allowed to use either `LHS` or `{ LHS }` as generic constants
|
||||
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-72787.rs:11:24
|
||||
|
|
||||
LL | Condition<{ LHS <= RHS }>: True
|
||||
@ -14,7 +14,7 @@ LL | Condition<{ LHS <= RHS }>: True
|
||||
|
|
||||
= help: it is currently only allowed to use either `RHS` or `{ RHS }` as generic constants
|
||||
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-72787.rs:26:25
|
||||
|
|
||||
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
|
||||
@ -22,7 +22,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
|
||||
|
|
||||
= help: it is currently only allowed to use either `I` or `{ I }` as generic constants
|
||||
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-72787.rs:26:36
|
||||
|
|
||||
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
|
||||
|
@ -10,8 +10,8 @@ pub trait True {}
|
||||
impl<const LHS: u32, const RHS: u32> True for IsLessOrEqual<LHS, RHS> where
|
||||
Condition<{ LHS <= RHS }>: True
|
||||
//[full]~^ Error constant expression depends on a generic parameter
|
||||
//[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
|
||||
//[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
|
||||
{
|
||||
}
|
||||
impl True for Condition<true> {}
|
||||
@ -28,8 +28,8 @@ where
|
||||
//[full]~| constant expression depends on a generic parameter
|
||||
//[full]~| constant expression depends on a generic parameter
|
||||
//[full]~| constant expression depends on a generic parameter
|
||||
//[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
|
||||
//[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
|
||||
// Condition<{ 8 - I <= 8 - J }>: True,
|
||||
{
|
||||
fn print() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-72819-generic-in-const-eval.rs:9:17
|
||||
|
|
||||
LL | where Assert::<{N < usize::max_value() / 2}>: IsTrue,
|
||||
|
@ -8,7 +8,7 @@
|
||||
struct Arr<const N: usize>
|
||||
where Assert::<{N < usize::max_value() / 2}>: IsTrue,
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-76701-ty-param-in-const.rs:6:46
|
||||
|
|
||||
LL | fn ty_param<T>() -> [u8; std::mem::size_of::<T>()] {
|
||||
@ -6,7 +6,7 @@ LL | fn ty_param<T>() -> [u8; std::mem::size_of::<T>()] {
|
||||
|
|
||||
= note: type parameters are currently not permitted in anonymous constants
|
||||
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/issue-76701-ty-param-in-const.rs:12:42
|
||||
|
|
||||
LL | fn const_param<const N: usize>() -> [u8; N + 1] {
|
||||
|
@ -5,13 +5,13 @@
|
||||
|
||||
fn ty_param<T>() -> [u8; std::mem::size_of::<T>()] {
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn const_param<const N: usize>() -> [u8; N + 1] {
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[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
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -7,19 +7,19 @@ fn ok<const M: usize>() -> [u8; M] {
|
||||
}
|
||||
|
||||
struct Break0<const N: usize>([u8; { N + 1 }]);
|
||||
//~^ ERROR generic parameters must not be used inside of non trivial constant values
|
||||
//~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
|
||||
struct Break1<const N: usize>([u8; { { N } }]);
|
||||
//~^ ERROR generic parameters must not be used inside of non trivial constant values
|
||||
//~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
|
||||
fn break2<const N: usize>() {
|
||||
let _: [u8; N + 1];
|
||||
//~^ ERROR generic parameters must not be used inside of non trivial constant values
|
||||
//~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
}
|
||||
|
||||
fn break3<const N: usize>() {
|
||||
let _ = [0; N + 1];
|
||||
//~^ ERROR generic parameters must not be used inside of non trivial constant values
|
||||
//~^ ERROR generic parameters must not be used inside of non-trivial constant values
|
||||
}
|
||||
|
||||
trait Foo {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/complex-expression.rs:9:38
|
||||
|
|
||||
LL | struct Break0<const N: usize>([u8; { N + 1 }]);
|
||||
@ -6,7 +6,7 @@ LL | struct Break0<const N: usize>([u8; { N + 1 }]);
|
||||
|
|
||||
= 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
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/complex-expression.rs:12:40
|
||||
|
|
||||
LL | struct Break1<const N: usize>([u8; { { N } }]);
|
||||
@ -14,7 +14,7 @@ LL | struct Break1<const N: usize>([u8; { { 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
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/complex-expression.rs:16:17
|
||||
|
|
||||
LL | let _: [u8; N + 1];
|
||||
@ -22,7 +22,7 @@ LL | let _: [u8; N + 1];
|
||||
|
|
||||
= 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
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/complex-expression.rs:21:17
|
||||
|
|
||||
LL | let _ = [0; N + 1];
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/self-ty-in-const-1.rs:4:41
|
||||
|
|
||||
LL | fn t1() -> [u8; std::mem::size_of::<Self>()];
|
||||
|
@ -0,0 +1,8 @@
|
||||
#![feature(min_const_generics)]
|
||||
|
||||
fn a<const X: &'static [u32]>() {}
|
||||
//~^ ERROR `&'static [u32]` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {
|
||||
a::<{&[]}>();
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
error: `&'static [u32]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/static-reference-array-const-param.rs:3:15
|
||||
|
|
||||
LL | fn a<const X: &'static [u32]>() {}
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= note: more complex types are supported with `#[feature(const_generics)]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -0,0 +1,12 @@
|
||||
#![feature(min_const_generics)]
|
||||
|
||||
struct Const<const P: &'static ()>;
|
||||
//~^ ERROR `&'static ()` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {
|
||||
const A: &'static () = unsafe {
|
||||
std::mem::transmute(10 as *const ())
|
||||
};
|
||||
|
||||
let _ = Const::<{A}>;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
error: `&'static ()` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/transmute-const-param-static-reference.rs:3:23
|
||||
|
|
||||
LL | struct Const<const P: &'static ()>;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= note: more complex types are supported with `#[feature(const_generics)]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -6,7 +6,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 must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:7:44
|
||||
|
|
||||
LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
|
||||
//[full]~^ ERROR constant values inside of type parameter defaults
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non trivial
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non-trivial
|
||||
|
||||
// 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);
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/wf-misc.rs:9:17
|
||||
|
|
||||
LL | let _: [u8; N + 1];
|
||||
@ -6,7 +6,7 @@ LL | let _: [u8; N + 1];
|
||||
|
|
||||
= 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
|
||||
error: generic parameters must not be used inside of non-trivial constant values
|
||||
--> $DIR/wf-misc.rs:17:21
|
||||
|
|
||||
LL | let _: Const::<{N + 1}>;
|
||||
|
@ -8,7 +8,7 @@
|
||||
pub fn arr_len<const N: usize>() {
|
||||
let _: [u8; N + 1];
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non trivial
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non-trivial
|
||||
}
|
||||
|
||||
struct Const<const N: usize>;
|
||||
@ -16,7 +16,7 @@ struct Const<const N: usize>;
|
||||
pub fn func_call<const N: usize>() {
|
||||
let _: Const::<{N + 1}>;
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non trivial
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non-trivial
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
Loading…
Reference in New Issue
Block a user