Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

min_const_generics diagnostics improvements #77825

Merged
merged 5 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 must not be used inside const evaluations",
eopb marked this conversation as resolved.
Show resolved Hide resolved
eopb marked this conversation as resolved.
Show resolved Hide resolved
);
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 anonymous constants");
eopb marked this conversation as resolved.
Show resolved Hide resolved
eopb marked this conversation as resolved.
Show resolved Hide resolved
} 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 `{}`",
eopb marked this conversation as resolved.
Show resolved Hide resolved
name
));
}

err
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `N`

error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `CFG`

error: `Config` is forbidden as the type of a const generic parameter
--> $DIR/array-size-in-generic-struct-param.rs:18:21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 const evaluations

#[derive(PartialEq, Eq)]
struct Config {
Expand All @@ -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 const evaluations
}

const C: Config = Config { arr_size: 5 };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/const-argument-if-length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 must not be used inside const evaluations
//[full]~^^ ERROR evaluation of constant value failed
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `N`

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -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 const evaluations

fn test<const N: usize>() -> Arr<N> where Arr<N>: Default {
//[full]~^ ERROR constant expression depends
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `N`

error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `N`

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `N`

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -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 const evaluations

fn test<const N: usize>() -> Arr<N> where Arr<N>: Sized {
todo!()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `N`

error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `N`

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -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 must not be used inside const evaluations
//[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 must not be used inside const evaluations
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `A`

error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `B`

error: aborting due to 2 previous errors

4 changes: 2 additions & 2 deletions src/test/ui/const-generics/generic-sum-in-array-length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 must not be used inside const evaluations
//[min]~| ERROR generic parameters must not be used inside const evaluations
//[full]~^^^ ERROR constant expression depends on a generic parameter

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 must not be used inside const evaluations
//[full]~^^ ERROR constant expression depends on a generic parameter
{
t: T
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/const-generics/issue-61522-array-len-succ.min.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `COUNT`

error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 `COUNT`

error: aborting due to 2 previous errors

6 changes: 3 additions & 3 deletions src/test/ui/const-generics/issue-67375.min.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 anonymous constants

error[E0392]: parameter `T` is never used
--> $DIR/issue-67375.rs:7:12
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issue-67375.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 must not be used inside const evaluations
//[full]~^^ WARN cannot use constants which depend on generic parameters in types
//[full]~^^^ WARN this was previously accepted by the compiler
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/const-generics/issue-67945-1.min.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 anonymous constants

error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 anonymous constants

error[E0392]: parameter `S` is never used
--> $DIR/issue-67945-1.rs:11:12
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issue-67945-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 must not be used inside const evaluations
//[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 must not be used inside const evaluations
0
}],
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/const-generics/issue-67945-2.min.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 anonymous constants

error: generic parameters must not be used inside of non-trivial constant values
error: generic parameters must not be used inside const evaluations
--> $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 anonymous constants

error[E0392]: parameter `S` is never used
--> $DIR/issue-67945-2.rs:9:12
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issue-67945-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 must not be used inside const evaluations
//[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 must not be used inside const evaluations
0
}],
}
Expand Down
Loading