Skip to content

Commit

Permalink
Fix duplicate error messages in const_generics tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Amjad50 committed Aug 31, 2020
1 parent 7a7a28d commit 668f63d
Show file tree
Hide file tree
Showing 23 changed files with 42 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/argument_order.full.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, const N: usize, T, const M: usize, U>`

error[E0747]: lifetime provided when a type was expected
--> $DIR/argument_order.rs:21:23
--> $DIR/argument_order.rs:20:23
|
LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
| ^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/argument_order.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
| ---------------------^----------------------^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`

error[E0747]: lifetime provided when a type was expected
--> $DIR/argument_order.rs:21:23
--> $DIR/argument_order.rs:20:23
|
LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
| ^^^^^^^
Expand Down
8 changes: 3 additions & 5 deletions src/test/ui/const-generics/argument_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ struct Bad<const N: usize, T> {
}

struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
//[full]~^ ERROR lifetime parameters must be declared prior
//[min]~^^ ERROR lifetime parameters must be declared prior to const parameters
//[min]~^^^ ERROR type parameters must be declared prior to const parameters
//~^ ERROR lifetime parameters must be declared prior
//[min]~^^ ERROR type parameters must be declared prior to const parameters
a: &'a T,
b: &'b U,
}

fn main() {
let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
//[full]~^ ERROR lifetime provided when a type was expected
//[min]~^^ ERROR lifetime provided when a type was expected
//~^ ERROR lifetime provided when a type was expected
}
3 changes: 1 addition & 2 deletions src/test/ui/const-generics/const-arg-type-arg-misordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
type Array<T, const N: usize> = [T; N];

fn foo<const N: usize>() -> Array<N, ()> {
//[full]~^ ERROR constant provided when a type was expected
//[min]~^^ ERROR constant provided when a type was expected
//~^ ERROR constant provided when a type was expected
unimplemented!()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | fn bar<const X: (), 'a>(_: &'a ()) {
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`

error: type parameters must be declared prior to const parameters
--> $DIR/const-param-before-other-params.rs:12:21
--> $DIR/const-param-before-other-params.rs:11:21
|
LL | fn foo<const X: (), T>(_: &T) {}
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`
Expand All @@ -20,7 +20,7 @@ LL | fn bar<const X: (), 'a>(_: &'a ()) {
= note: more complex types are supported with `#[feature(const_generics)]`

error: `()` is forbidden as the type of a const generic parameter
--> $DIR/const-param-before-other-params.rs:12:17
--> $DIR/const-param-before-other-params.rs:11:17
|
LL | fn foo<const X: (), T>(_: &T) {}
| ^^
Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/const-generics/const-param-before-other-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#![cfg_attr(min, feature(min_const_generics))]

fn bar<const X: (), 'a>(_: &'a ()) {
//[full]~^ ERROR lifetime parameters must be declared prior to const parameters
//[min]~^^ ERROR lifetime parameters must be declared prior to const parameters
//[min]~^^^ ERROR `()` is forbidden as the type of a const generic parameter
//~^ ERROR lifetime parameters must be declared prior to const parameters
//[min]~^^ ERROR `()` is forbidden as the type of a const generic parameter
}

fn foo<const X: (), T>(_: &T) {}
Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ struct B;
impl A for B {}

fn test<const T: &'static dyn A>() {
//[full]~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]` to be used
//[min]~^^ ERROR `&'static (dyn A + 'static)` is forbidden as the type of
// a const generic parameter
//[min]~| ERROR must be annotated with `#[derive(PartialEq, Eq)]` to be used
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]` to be used
//[min]~^^ ERROR `&'static (dyn A + 'static)` is forbidden
unimplemented!()
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/issues/issue-71169.full.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
| ^^^ the type must not depend on the parameter `LEN`

error: constant expression depends on a generic parameter
--> $DIR/issue-71169.rs:12:14
--> $DIR/issue-71169.rs:11:14
|
LL | foo::<4, DATA>();
| ^^^^
Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/const-generics/issues/issue-71169.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#![cfg_attr(min, feature(min_const_generics))]

fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
//[full]~^ ERROR the type of const parameters must not
//[min]~^^ ERROR the type of const parameters must not
//[min]~| ERROR `[u8; _]` is forbidden as the type of a const generic parameter
//~^ ERROR the type of const parameters must not
//[min]~^^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
fn main() {
const DATA: [u8; 4] = *b"ABCD";
foo::<4, DATA>();
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issues/issue-71381.full.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
| ^^^^ the type must not depend on the parameter `Args`

error[E0770]: the type of const parameters must not depend on other generic parameters
--> $DIR/issue-71381.rs:26:40
--> $DIR/issue-71381.rs:24:40
|
LL | const FN: unsafe extern "C" fn(Args),
| ^^^^ the type must not depend on the parameter `Args`
Expand All @@ -17,7 +17,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-71381.rs:26:19
--> $DIR/issue-71381.rs:24:19
|
LL | const FN: unsafe extern "C" fn(Args),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issues/issue-71381.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
| ^^^^ the type must not depend on the parameter `Args`

error[E0770]: the type of const parameters must not depend on other generic parameters
--> $DIR/issue-71381.rs:26:40
--> $DIR/issue-71381.rs:24:40
|
LL | const FN: unsafe extern "C" fn(Args),
| ^^^^ the type must not depend on the parameter `Args`
Expand All @@ -17,7 +17,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-71381.rs:26:19
--> $DIR/issue-71381.rs:24:19
|
LL | const FN: unsafe extern "C" fn(Args),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 4 additions & 8 deletions src/test/ui/const-generics/issues/issue-71381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ unsafe extern "C" fn pass(args: PassArg) {

impl Test {
pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
//[full]~^ ERROR: using function pointers as const generic parameters is forbidden
//[full]~| ERROR: the type of const parameters must not depend on other generic parameters
//[min]~^^^ ERROR: using function pointers as const generic parameters is forbidden
//[min]~| ERROR: the type of const parameters must not depend on other generic parameters
//~^ ERROR: using function pointers as const generic parameters is forbidden
//~| ERROR: the type of const parameters must not depend on other generic parameters
self.0 = Self::trampiline::<Args, IDX, FN> as _
}

unsafe extern "C" fn trampiline<
Args: Sized,
const IDX: usize,
const FN: unsafe extern "C" fn(Args),
//[full]~^ ERROR: using function pointers as const generic parameters is forbidden
//[full]~| ERROR: the type of const parameters must not depend on other generic parameters
//[min]~^^^ ERROR: using function pointers as const generic parameters is forbidden
//[min]~| ERROR: the type of const parameters must not depend on other generic parameters
//~^ ERROR: using function pointers as const generic parameters is forbidden
//~| ERROR: the type of const parameters must not depend on other generic parameters
>(
args: Args,
) {
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/const-generics/issues/issue-71382.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ impl Test {
}

fn test<const FN: fn()>(&self) {
//[full]~^ ERROR: using function pointers as const generic parameters is forbidden
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
//~^ ERROR: using function pointers as const generic parameters is forbidden
FN();
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/const-generics/issues/issue-71611.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
#![cfg_attr(min, feature(min_const_generics))]

fn func<A, const F: fn(inner: A)>(outer: A) {
//[full]~^ ERROR: using function pointers as const generic parameters is forbidden
//[full]~| ERROR: the type of const parameters must not depend on other generic parameters
//[min]~^^^ ERROR: using function pointers as const generic parameters is forbidden
//[min]~| ERROR: the type of const parameters must not depend on other generic parameters
//~^ ERROR: using function pointers as const generic parameters is forbidden
//~| ERROR: the type of const parameters must not depend on other generic parameters
F(outer);
}

Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/const-generics/issues/issue-72352.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use std::ffi::{CStr, CString};

unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
//[full]~^ ERROR: using function pointers as const generic parameters is forbidden
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
//~^ ERROR: using function pointers as const generic parameters is forbidden
F(CStr::from_ptr(ptr))
}

Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/const-generics/issues/issue-73508.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(min, feature(min_const_generics))]

pub const fn func_name<const X: *const u32>() {}
//[full]~^ ERROR using raw pointers
//[min]~^^ ERROR using raw pointers as const generic parameters is forbidden
//~^ ERROR using raw pointers

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LL | struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;
= note: more complex types are supported with `#[feature(const_generics)]`

error: `std::ops::RangeTo<usize>` is forbidden as the type of a const generic parameter
--> $DIR/const-generics-range.rs:30:26
--> $DIR/const-generics-range.rs:29:26
|
LL | struct _RangeTo<const R: std::ops::RangeTo<usize>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -44,7 +44,7 @@ LL | struct _RangeTo<const R: std::ops::RangeTo<usize>>;
= note: more complex types are supported with `#[feature(const_generics)]`

error: `std::ops::RangeToInclusive<usize>` is forbidden as the type of a const generic parameter
--> $DIR/const-generics-range.rs:35:35
--> $DIR/const-generics-range.rs:34:35
|
LL | struct _RangeToInclusive<const R: std::ops::RangeToInclusive<usize>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
14 changes: 6 additions & 8 deletions src/test/ui/const-generics/std/const-generics-range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,33 @@

// `Range` should be usable within const generics:
struct _Range<const R: std::ops::Range<usize>>;
//[min]~^ ERROR `std::ops::Range<usize>` is forbidden as the type of a const generic parameter
//[min]~^ ERROR `std::ops::Range<usize>` is forbidden
const RANGE : _Range<{ 0 .. 1000 }> = _Range;

// `RangeFrom` should be usable within const generics:
struct _RangeFrom<const R: std::ops::RangeFrom<usize>>;
//[min]~^ ERROR `std::ops::RangeFrom<usize>` is forbidden as the type of a const generic parameter
//[min]~^ ERROR `std::ops::RangeFrom<usize>` is forbidden
const RANGE_FROM : _RangeFrom<{ 0 .. }> = _RangeFrom;

// `RangeFull` should be usable within const generics:
struct _RangeFull<const R: std::ops::RangeFull>;
//[min]~^ ERROR `std::ops::RangeFull` is forbidden as the type of a const generic parameter
//[min]~^ ERROR `std::ops::RangeFull` is forbidden
const RANGE_FULL : _RangeFull<{ .. }> = _RangeFull;

// Regression test for #70155
// `RangeInclusive` should be usable within const generics:
struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;
//[min]~^ ERROR `std::ops::RangeInclusive<usize>` is forbidden as the type of a const generic
// parameter
//[min]~^ ERROR `std::ops::RangeInclusive<usize>` is forbidden
const RANGE_INCLUSIVE : _RangeInclusive<{ 0 ..= 999 }> = _RangeInclusive;

// `RangeTo` should be usable within const generics:
struct _RangeTo<const R: std::ops::RangeTo<usize>>;
//[min]~^ ERROR `std::ops::RangeTo<usize>` is forbidden as the type of a const generic parameter
//[min]~^ ERROR `std::ops::RangeTo<usize>` is forbidden
const RANGE_TO : _RangeTo<{ .. 1000 }> = _RangeTo;

// `RangeToInclusive` should be usable within const generics:
struct _RangeToInclusive<const R: std::ops::RangeToInclusive<usize>>;
//[min]~^ ERROR `std::ops::RangeToInclusive<usize>` is forbidden as the type of a const generic
// parameter
//[min]~^ ERROR `std::ops::RangeToInclusive<usize>` is forbidden
const RANGE_TO_INCLUSIVE : _RangeToInclusive<{ ..= 999 }> = _RangeToInclusive;

pub fn main() {}
3 changes: 1 addition & 2 deletions src/test/ui/const-generics/type-dependent/issue-71382.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ impl Test {
}

fn test<const FN: fn() -> u8>(&self) -> u8 {
//[full]~^ ERROR using function pointers as const generic parameters is forbidden
//[min]~^^ ERROR using function pointers as const generic parameters is forbidden
//~^ ERROR using function pointers as const generic parameters is forbidden
FN()
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/const-generics/type-dependent/type-mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ impl R {
}
fn main() {
assert_eq!(R.method::<1u16>(), 1);
//[full]~^ ERROR mismatched types
//[min]~^^ ERROR mismatched types
//~^ ERROR mismatched types
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data
found type `4_u32`

error[E0308]: mismatched types
--> $DIR/types-mismatch-const-args.rs:18:41
--> $DIR/types-mismatch-const-args.rs:17:41
|
LL | let _: A<'a, u16, {2u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData };
| -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u16`, found `u32`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LL | let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data
found struct `A<'_, _, 4_u32, _>`

error[E0308]: mismatched types
--> $DIR/types-mismatch-const-args.rs:18:41
--> $DIR/types-mismatch-const-args.rs:17:41
|
LL | let _: A<'a, u16, {2u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData };
| -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u16`, found `u32`
Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/const-generics/types-mismatch-const-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ struct A<'a, T, const X: u32, const Y: u32> {

fn a<'a, 'b>() {
let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data: PhantomData };
//[full]~^ ERROR mismatched types
//[min]~^^ ERROR mismatched types
//~^ ERROR mismatched types
let _: A<'a, u16, {2u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData };
//[full]~^ ERROR mismatched types
//[min]~^^ ERROR mismatched types
//~^ ERROR mismatched types
}

pub fn main() {}

0 comments on commit 668f63d

Please sign in to comment.