Rollup merge of #77825 - ethanboxx:min_const_generics_diagnostic, r=lcnr

`min_const_generics` diagnostics improvements

As disscussed in [zulip/project-const-generics/non-trivial anonymous constant](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants).

This is my first PR on the compiler.

@lcnr is mentoring me on this PR.

Related to #60551.
This commit is contained in:
Yuki Okushi 2020-10-14 06:02:29 +09:00 committed by GitHub
commit c44cc7e236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
56 changed files with 185 additions and 192 deletions

View File

@ -469,24 +469,17 @@ 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",
);
err.span_label(
span,
&format!(
"non-trivial anonymous constants must not depend on the parameter `{}`",
name
),
"generic parameters may not be used in const operations",
);
err.span_label(span, &format!("cannot perform const operation using `{}`", name));
if is_type {
err.note("type parameters are currently not permitted in anonymous constants");
err.note("type parameters may not be used in const expressions");
} else {
err.help(
&format!("it is currently only allowed to use either `{0}` or `{{ {0} }}` as generic constants",
name
)
);
err.help(&format!(
"const parameters may only be used as standalone arguments, i.e. `{}`",
name
));
}
err

View File

@ -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 const evaluations.
///
/// This error is only emitted when using `min_const_generics`.
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/array-size-in-generic-struct-param.rs:9:48
|
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/array-size-in-generic-struct-param.rs:20:15
|
LL | arr: [u8; CFG.arr_size],
| ^^^ non-trivial anonymous constants must not depend on the parameter `CFG`
| ^^^ cannot perform const operation using `CFG`
|
= help: it is currently only allowed to use either `CFG` or `{ CFG }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `CFG`
error: `Config` is forbidden as the type of a const generic parameter
--> $DIR/array-size-in-generic-struct-param.rs:18:21

View File

@ -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 may not be used in const operations
#[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 may not be used in const operations
}
const C: Config = Config { arr_size: 5 };

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $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`
| ^ cannot perform const operation using `T`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/const-argument-if-length.rs:17:12

View File

@ -17,7 +17,7 @@ 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
//[min]~^ ERROR generic parameters may not be used in const operations
//[full]~^^ ERROR evaluation of constant value failed
}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/feature-gate-const_evaluatable_checked.rs:6:33
|
LL | type Arr<const N: usize> = [u8; N - 1];
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to previous error

View File

@ -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 may not be used in const operations
fn test<const N: usize>() -> Arr<N> where Arr<N>: Default {
//[full]~^ ERROR constant expression depends

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/simple.rs:8:53
|
LL | fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/simple.rs:8:35
|
LL | fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to 2 previous errors

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/simple_fail.rs:7:33
|
LL | type Arr<const N: usize> = [u8; N - 1];
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to previous error

View File

@ -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 may not be used in const operations
fn test<const N: usize>() -> Arr<N> where Arr<N>: Sized {
todo!()

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $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`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $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`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to 2 previous errors

View File

@ -7,10 +7,10 @@
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
//[min]~^ ERROR generic parameters may not be used in const operations
//[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
//[min]~^ ERROR generic parameters may not be used in const operations
}
fn main() {}

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $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`
| ^ cannot perform const operation using `A`
|
= help: it is currently only allowed to use either `A` or `{ A }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `A`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $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`
| ^ cannot perform const operation using `B`
|
= help: it is currently only allowed to use either `B` or `{ B }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `B`
error: aborting due to 2 previous errors

View File

@ -5,8 +5,8 @@
#![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
//[min]~^ ERROR generic parameters may not be used in const operations
//[min]~| ERROR generic parameters may not be used in const operations
//[full]~^^^ ERROR constant expression depends on a generic parameter
fn main() {}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $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`
| ^ cannot perform const operation using `T`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error: `&'static str` is forbidden as the type of a const generic parameter
--> $DIR/intrinsics-type_name-as-const-argument.rs:10:22

View File

@ -13,7 +13,7 @@ trait Trait<const S: &'static str> {}
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
//[min]~^ ERROR generic parameters may not be used in const operations
//[full]~^^ ERROR constant expression depends on a generic parameter
{
t: T

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-61522-array-len-succ.rs:7:45
|
LL | pub struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
| ^^^^^ non-trivial anonymous constants must not depend on the parameter `COUNT`
| ^^^^^ cannot perform const operation using `COUNT`
|
= help: it is currently only allowed to use either `COUNT` or `{ COUNT }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `COUNT`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-61522-array-len-succ.rs:12:30
|
LL | fn inner(&self) -> &[u8; COUNT + 1] {
| ^^^^^ non-trivial anonymous constants must not depend on the parameter `COUNT`
| ^^^^^ cannot perform const operation using `COUNT`
|
= help: it is currently only allowed to use either `COUNT` or `{ COUNT }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `COUNT`
error: aborting due to 2 previous errors

View File

@ -6,12 +6,12 @@
pub struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
//[full]~^ ERROR constant expression depends on a generic parameter
//[min]~^^ ERROR generic parameters must not be used
//[min]~^^ ERROR generic parameters may not be used
impl<const COUNT: usize> MyArray<COUNT> {
fn inner(&self) -> &[u8; COUNT + 1] {
//[full]~^ ERROR constant expression depends on a generic parameter
//[min]~^^ ERROR generic parameters must not be used
//[min]~^^ ERROR generic parameters may not be used
&self.0
}
}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-67375.rs:9:25
|
LL | inner: [(); { [|_: &T| {}; 0].len() }],
| ^ non-trivial anonymous constants must not depend on the parameter `T`
| ^ cannot perform const operation using `T`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error[E0392]: parameter `T` is never used
--> $DIR/issue-67375.rs:7:12

View File

@ -7,7 +7,7 @@
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
//[min]~^ ERROR generic parameters may not be used in const operations
//[full]~^^ WARN cannot use constants which depend on generic parameters in types
//[full]~^^^ WARN this was previously accepted by the compiler
}

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-67945-1.rs:14:16
|
LL | let x: S = MaybeUninit::uninit();
| ^ non-trivial anonymous constants must not depend on the parameter `S`
| ^ cannot perform const operation using `S`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $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`
| ^ cannot perform const operation using `S`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error[E0392]: parameter `S` is never used
--> $DIR/issue-67945-1.rs:11:12

View File

@ -12,10 +12,10 @@ 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
//[min]~^ ERROR generic parameters may not be used in const operations
//[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
//[min]~^ ERROR generic parameters may not be used in const operations
0
}],
}

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-67945-2.rs:12:16
|
LL | let x: S = MaybeUninit::uninit();
| ^ non-trivial anonymous constants must not depend on the parameter `S`
| ^ cannot perform const operation using `S`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $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`
| ^ cannot perform const operation using `S`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error[E0392]: parameter `S` is never used
--> $DIR/issue-67945-2.rs:9:12

View File

@ -10,10 +10,10 @@ 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
//[min]~^ ERROR generic parameters may not be used in const operations
//[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
//[min]~^ ERROR generic parameters may not be used in const operations
0
}],
}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-61747.rs:8:30
|
LL | fn successor() -> Const<{C + 1}> {
| ^ non-trivial anonymous constants must not depend on the parameter `C`
| ^ cannot perform const operation using `C`
|
= help: it is currently only allowed to use either `C` or `{ C }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `C`
error: aborting due to previous error

View File

@ -7,7 +7,7 @@ struct Const<const N: usize>;
impl<const C: usize> Const<{C}> {
fn successor() -> Const<{C + 1}> {
//[full]~^ ERROR constant expression depends on a generic parameter
//[min]~^^ ERROR generic parameters must not be used
//[min]~^^ ERROR generic parameters may not be used
Const
}
}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-61935.rs:10:23
|
LL | Self:FooImpl<{N==0}>
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to previous error

View File

@ -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 may not be used in const operations
{}
trait FooImpl<const IS_ZERO: bool>{}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-62220.rs:8:59
|
LL | pub type TruncatedVector<T, const N: usize> = Vector<T, { N - 1 }>;
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to previous error

View File

@ -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 may not be used in const operations
impl<T, const N: usize> Vector<T, { N }> {
/// Drop the last component and return the vector with one fewer dimension.

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-62456.rs:7:20
|
LL | let _ = [0u64; N + 1];
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to previous error

View File

@ -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 may not be used in const operations
}
fn main() {}

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-64494.rs:16:38
|
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 5}>: True {}
| ^^^^^^ non-trivial anonymous constants must not depend on the parameter `T`
| ^^^^^^ cannot perform const operation using `T`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-64494.rs:19:38
|
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 6}>: True {}
| ^^^^^^ non-trivial anonymous constants must not depend on the parameter `T`
| ^^^^^^ cannot perform const operation using `T`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error[E0119]: conflicting implementations of trait `MyTrait`:
--> $DIR/issue-64494.rs:19:1

View File

@ -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 may not be used in const operations
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 may not be used in const operations
//[min]~| ERROR conflicting implementations of trait `MyTrait`
fn main() {}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-66205.rs:8:14
|
LL | fact::<{ N - 1 }>();
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to previous error

View File

@ -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 may not be used in const operations
}
fn main() {}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-67739.rs:12:30
|
LL | [0u8; mem::size_of::<Self::Associated>()];
| ^^^^^^^^^^^^^^^^ non-trivial anonymous constants must not depend on the parameter `Self`
| ^^^^^^^^^^^^^^^^ cannot perform const operation using `Self`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error: aborting due to previous error

View File

@ -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 may not be used in const operations
0
}
}

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-68366.rs:12:37
|
LL | impl <const N: usize> Collatz<{Some(N)}> {}
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-68366.rs:12:13

View File

@ -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 may not be used in const operations
struct Foo;

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-68977.rs:29:17
|
LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
| ^^^^^^^^ non-trivial anonymous constants must not depend on the parameter `INT_BITS`
| ^^^^^^^^ cannot perform const operation using `INT_BITS`
|
= help: it is currently only allowed to use either `INT_BITS` or `{ INT_BITS }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `INT_BITS`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-68977.rs:29:28
|
LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
| ^^^^^^^^^ non-trivial anonymous constants must not depend on the parameter `FRAC_BITS`
| ^^^^^^^^^ cannot perform const operation using `FRAC_BITS`
|
= help: it is currently only allowed to use either `FRAC_BITS` or `{ FRAC_BITS }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `FRAC_BITS`
error: aborting due to 2 previous errors

View File

@ -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 may not be used in const operations
//[min]~| ERROR generic parameters may not be used in const operations
struct Fxp<const INT_BITS: u8, const FRAC_BITS: u8>
where

View File

@ -1,34 +1,34 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-72787.rs:11:17
|
LL | Condition<{ LHS <= RHS }>: True
| ^^^ non-trivial anonymous constants must not depend on the parameter `LHS`
| ^^^ cannot perform const operation using `LHS`
|
= help: it is currently only allowed to use either `LHS` or `{ LHS }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `LHS`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-72787.rs:11:24
|
LL | Condition<{ LHS <= RHS }>: True
| ^^^ non-trivial anonymous constants must not depend on the parameter `RHS`
| ^^^ cannot perform const operation using `RHS`
|
= help: it is currently only allowed to use either `RHS` or `{ RHS }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `RHS`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-72787.rs:26:25
|
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
| ^ non-trivial anonymous constants must not depend on the parameter `I`
| ^ cannot perform const operation using `I`
|
= help: it is currently only allowed to use either `I` or `{ I }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `I`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-72787.rs:26:36
|
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
| ^ non-trivial anonymous constants must not depend on the parameter `J`
| ^ cannot perform const operation using `J`
|
= help: it is currently only allowed to use either `J` or `{ J }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `J`
error[E0283]: type annotations needed
--> $DIR/issue-72787.rs:22:26

View File

@ -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 may not be used in const operations
//[min]~| Error generic parameters may not be used in const operations
{
}
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 may not be used in const operations
//[min]~| Error generic parameters may not be used in const operations
// Condition<{ 8 - I <= 8 - J }>: True,
{
fn print() {

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-72819-generic-in-const-eval.rs:9:17
|
LL | where Assert::<{N < usize::max_value() / 2}>: IsTrue,
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to previous error

View File

@ -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 may not be used in const operations
{
}

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-76701-ty-param-in-const.rs:6:46
|
LL | fn ty_param<T>() -> [u8; std::mem::size_of::<T>()] {
| ^ non-trivial anonymous constants must not depend on the parameter `T`
| ^ cannot perform const operation using `T`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/issue-76701-ty-param-in-const.rs:12:42
|
LL | fn const_param<const N: usize>() -> [u8; N + 1] {
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to 2 previous errors

View File

@ -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 may not be used in const operations
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 may not be used in const operations
todo!()
}

View File

@ -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 may not be used in const operations
struct Break1<const N: usize>([u8; { { N } }]);
//~^ ERROR generic parameters must not be used inside of non-trivial constant values
//~^ ERROR generic parameters may not be used in const operations
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 may not be used in const operations
}
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 may not be used in const operations
}
trait Foo {

View File

@ -1,34 +1,34 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/complex-expression.rs:9:38
|
LL | struct Break0<const N: usize>([u8; { N + 1 }]);
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/complex-expression.rs:12:40
|
LL | struct Break1<const N: usize>([u8; { { N } }]);
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/complex-expression.rs:16:17
|
LL | let _: [u8; N + 1];
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/complex-expression.rs:21:17
|
LL | let _ = [0; N + 1];
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to 4 previous errors

View File

@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/self-ty-in-const-1.rs:4:41
|
LL | fn t1() -> [u8; std::mem::size_of::<Self>()];
| ^^^^ non-trivial anonymous constants must not depend on the parameter `Self`
| ^^^^ cannot perform const operation using `Self`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error: generic `Self` types are currently not permitted in anonymous constants
--> $DIR/self-ty-in-const-1.rs:14:41

View File

@ -6,13 +6,13 @@ 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 may not be used in const operations
--> $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);
| ^ non-trivial anonymous constants must not depend on the parameter `T`
| ^ cannot perform const operation using `T`
|
= note: type parameters are currently not permitted in anonymous constants
= note: type parameters may not be used in const expressions
error: constant values inside of type parameter defaults must not depend on generic parameters
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:12:21

View File

@ -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 may not be used in const operations
// 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);

View File

@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/wf-misc.rs:9:17
|
LL | let _: [u8; N + 1];
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters may not be used in const operations
--> $DIR/wf-misc.rs:17:21
|
LL | let _: Const::<{N + 1}>;
| ^ non-trivial anonymous constants must not depend on the parameter `N`
| ^ cannot perform const operation using `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
= help: const parameters may only be used as standalone arguments, i.e. `N`
error: aborting due to 2 previous errors

View File

@ -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 may not be used in const operations
}
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 may not be used in const operations
}
fn main() {}