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

Fix missing diagnostic span for impl Trait with const generics, and add various tests for min_const_generics and const_generics #77439

Merged
merged 7 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 of non-trivial constant values.
///
/// This error is only emitted when using `min_const_generics`.
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/astconv/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>>();
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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]);
| ^ 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
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],
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 of non-trivial constant values

#[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 of non-trivial
}

const C: Config = Config { arr_size: 5 };
Expand Down
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
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 of non-trivial constant values

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,12 +1,12 @@
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 {
| ^ 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
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
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 of non-trivial constant values

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,12 +1,12 @@
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]);
| ^^^^^ non-trivial anonymous constants must not depend on the parameter `COUNT`
|
= 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] {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-61747.min.stderr
Original file line number Diff line number Diff line change
@@ -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}> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-61935.min.stderr
Original file line number Diff line number Diff line change
@@ -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}>
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-61935.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>{}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-62220.min.stderr
Original file line number Diff line number Diff line change
@@ -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 }>;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-62220.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-62456.min.stderr
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-62456.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issues/issue-64494.min.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 {}
| ^^^^^^ non-trivial anonymous constants must not depend on the parameter `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-64494.rs:19:38
|
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 6}>: True {}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issues/issue-64494.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-66205.min.stderr
Original file line number Diff line number Diff line change
@@ -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 }>();
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-66205.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-67739.min.stderr
Original file line number Diff line number Diff line change
@@ -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>()];
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-67739.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-68366.min.stderr
Original file line number Diff line number Diff line change
@@ -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)}> {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-68366.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issues/issue-68977.min.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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}>;
| ^^^^^^^^ non-trivial anonymous constants must not depend on the parameter `INT_BITS`
|
= 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}>;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issues/issue-68977.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/const-generics/issues/issue-72787.min.stderr
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
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
| ^^^ non-trivial anonymous constants must not depend on the parameter `LHS`
|
= 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
| ^^^ non-trivial anonymous constants must not depend on the parameter `RHS`
|
= 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,
| ^ non-trivial anonymous constants must not depend on the parameter `I`
|
= 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,
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/const-generics/issues/issue-72787.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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>()] {
| ^ non-trivial anonymous constants must not depend on the parameter `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] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
}

Expand Down
Loading