Skip to content

Commit be650a7

Browse files
committed
Add a bunch of revisions
This adds a bunch of revisions to const-generic tests
1 parent c94ed5c commit be650a7

31 files changed

+305
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: using raw pointers as const generic parameters is forbidden
2+
--> $DIR/raw-ptr-const-param-deref.rs:10:23
3+
|
4+
LL | struct Const<const P: *const u32>;
5+
| ^^^^^^^^^^
6+
7+
error: using raw pointers as const generic parameters is forbidden
8+
--> $DIR/raw-ptr-const-param-deref.rs:12:15
9+
|
10+
LL | impl<const P: *const u32> Const<P> {
11+
| ^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: using raw pointers as const generic parameters is forbidden
2+
--> $DIR/raw-ptr-const-param-deref.rs:10:23
3+
|
4+
LL | struct Const<const P: *const u32>;
5+
| ^^^^^^^^^^
6+
|
7+
= note: the only supported types are integers, `bool` and `char`
8+
= note: more complex types are supported with `#[feature(const_generics)]`
9+
10+
error: using raw pointers as const generic parameters is forbidden
11+
--> $DIR/raw-ptr-const-param-deref.rs:12:15
12+
|
13+
LL | impl<const P: *const u32> Const<P> {
14+
| ^^^^^^^^^^
15+
|
16+
= note: the only supported types are integers, `bool` and `char`
17+
= note: more complex types are supported with `#[feature(const_generics)]`
18+
19+
error: aborting due to 2 previous errors
20+

src/test/ui/const-generics/raw-ptr-const-param-deref.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
1+
// Assert that cannot use const generics as ptrs and cannot deref them.
2+
// revisions: full min
3+
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
37

48
const A: u32 = 3;
59

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: using raw pointers as const generic parameters is forbidden
2+
--> $DIR/raw-ptr-const-param.rs:7:23
3+
|
4+
LL | struct Const<const P: *const u32>;
5+
| ^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: using raw pointers as const generic parameters is forbidden
2+
--> $DIR/raw-ptr-const-param.rs:7:23
3+
|
4+
LL | struct Const<const P: *const u32>;
5+
| ^^^^^^^^^^
6+
|
7+
= note: the only supported types are integers, `bool` and `char`
8+
= note: more complex types are supported with `#[feature(const_generics)]`
9+
10+
error: aborting due to previous error
11+

src/test/ui/const-generics/raw-ptr-const-param.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
1+
// revisions: full min
2+
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(full, allow(incomplete_features))]
5+
#![cfg_attr(min, feature(min_const_generics))]
36

47
struct Const<const P: *const u32>; //~ ERROR: using raw pointers as const generic parameters
58

src/test/ui/const-generics/slice-const-param-mismatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
2+
#![allow(incomplete_features)]
33

44
struct ConstString<const T: &'static str>;
55
struct ConstBytes<const T: &'static [u8]>;

src/test/ui/const-generics/slice-const-param-mismatch.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/slice-const-param-mismatch.rs:1:12
3-
|
4-
LL | #![feature(const_generics)]
5-
| ^^^^^^^^^^^^^^
6-
|
7-
= note: `#[warn(incomplete_features)]` on by default
8-
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
9-
101
error[E0308]: mismatched types
112
--> $DIR/slice-const-param-mismatch.rs:9:35
123
|
@@ -40,6 +31,6 @@ LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
4031
= note: expected struct `ConstBytes<b"AAA">`
4132
found struct `ConstBytes<b"BBB">`
4233

43-
error: aborting due to 3 previous errors; 1 warning emitted
34+
error: aborting due to 3 previous errors
4435

4536
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: using `&'static str` as const generic parameters is forbidden
2+
--> $DIR/slice-const-param.rs:8:40
3+
|
4+
LL | pub fn function_with_str<const STRING: &'static str>() -> &'static str {
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: the only supported types are integers, `bool` and `char`
8+
= note: more complex types are supported with `#[feature(const_generics)]`
9+
10+
error: using `&'static [u8]` as const generic parameters is forbidden
11+
--> $DIR/slice-const-param.rs:13:41
12+
|
13+
LL | pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
14+
| ^^^^^^^^^^^^^
15+
|
16+
= note: the only supported types are integers, `bool` and `char`
17+
= note: more complex types are supported with `#[feature(const_generics)]`
18+
19+
error: aborting due to 2 previous errors
20+

src/test/ui/const-generics/slice-const-param.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
// run-pass
1+
//[full] run-pass
2+
// revisions: min full
23

3-
#![feature(const_generics)]
4-
//~^ WARN the feature `const_generics` is incomplete
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
57

68
pub fn function_with_str<const STRING: &'static str>() -> &'static str {
9+
//[min]~^ ERROR using `&'static str` as const
710
STRING
811
}
912

1013
pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
14+
//[min]~^ ERROR using `&'static [u8]` as const
1115
BYTES
1216
}
1317

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0573]: expected type, found const parameter `C`
2+
--> $DIR/struct-with-invalid-const-param.rs:8:23
3+
|
4+
LL | struct S<const C: u8>(C);
5+
| ----------------------^--
6+
| | |
7+
| | help: a struct with a similar name exists: `S`
8+
| similarly named struct `S` defined here
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0573`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0573]: expected type, found const parameter `C`
2+
--> $DIR/struct-with-invalid-const-param.rs:8:23
3+
|
4+
LL | struct S<const C: u8>(C);
5+
| ----------------------^--
6+
| | |
7+
| | help: a struct with a similar name exists: `S`
8+
| similarly named struct `S` defined here
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0573`.

src/test/ui/const-generics/struct-with-invalid-const-param.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
1+
// Checks that a const param cannot be stored in a struct.
2+
// revisions: full min
3+
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
37

48
struct S<const C: u8>(C); //~ ERROR expected type, found const parameter
59

src/test/ui/const-generics/trait-const-args.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// check-pass
2-
#![allow(incomplete_features)]
3-
#![feature(const_generics)]
2+
// revisions: full min
3+
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
47

58
struct Const<const N: usize>;
69
trait Foo<const N: usize> {}

src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
2+
// revisions: full min
23

3-
#![feature(const_generics)]
4-
//~^ WARN the feature `const_generics` is incomplete
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
57

68
use std::mem::MaybeUninit;
79

src/test/ui/const-generics/type_of_anon_const.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
2+
// revisions: full min
23

3-
#![feature(const_generics)]
4-
//~^ WARN the feature `const_generics` is incomplete
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
57

68
trait T<const A: usize> {
79
fn l<const N: bool>() -> usize;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/uninferred-consts.rs:14:5
3+
|
4+
LL | Foo.foo();
5+
| ^^^^^^^^^
6+
|
7+
= note: unable to infer the value of a const parameter
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/uninferred-consts.rs:14:5
3+
|
4+
LL | Foo.foo();
5+
| ^^^^^^^^^
6+
|
7+
= note: unable to infer the value of a const parameter
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.

src/test/ui/const-generics/uninferred-consts.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
1+
// Test if emits error if cannot properly infer constant.
2+
// revisions: full min
3+
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
37

48
// taken from https://github.com/rust-lang/rust/issues/70507#issuecomment-615268893
59
struct Foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `UnknownStruct` in this scope
2+
--> $DIR/unknown_adt.rs:10:12
3+
|
4+
LL | let _: UnknownStruct<7>;
5+
| ^^^^^^^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `UnknownStruct` in this scope
2+
--> $DIR/unknown_adt.rs:10:12
3+
|
4+
LL | let _: UnknownStruct<7>;
5+
| ^^^^^^^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.

src/test/ui/const-generics/unknown_adt.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
#![feature(const_generics)]
2-
#![allow(incomplete_features)]
1+
// Checks errors when there is an abstract data type.
2+
// revisions: full min
3+
4+
5+
#![cfg_attr(full, feature(const_generics))]
6+
#![cfg_attr(full, allow(incomplete_features))]
7+
#![cfg_attr(min, feature(min_const_generics))]
38

49
fn main() {
510
let _: UnknownStruct<7>;

src/test/ui/const-generics/unused-const-param.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// check-pass
2+
// revisions: full min
23

3-
#![feature(const_generics)]
4-
//~^ WARN the feature `const_generics` is incomplete
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
57

68
struct A<const N: usize>; // ok
79

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
// run-rustfix
3+
// revisions: full min
4+
5+
#![cfg_attr(full, feature(const_generics))]
6+
#![cfg_attr(full, allow(incomplete_features))]
7+
#![cfg_attr(min, feature(min_const_generics))]
8+
#![warn(unused_braces)]
9+
10+
11+
struct A<const N: usize>;
12+
13+
fn main() {
14+
let _: A<7>; // ok
15+
let _: A< 7 >; //~ WARN unnecessary braces
16+
let _: A<{ 3 + 5 }>; // ok
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: unnecessary braces around const expression
2+
--> $DIR/unused_braces.rs:15:14
3+
|
4+
LL | let _: A<{ 7 }>;
5+
| ^^^^^ help: remove these braces
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused_braces.rs:8:9
9+
|
10+
LL | #![warn(unused_braces)]
11+
| ^^^^^^^^^^^^^
12+
13+
warning: 1 warning emitted
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
// run-rustfix
3+
// revisions: full min
4+
5+
#![cfg_attr(full, feature(const_generics))]
6+
#![cfg_attr(full, allow(incomplete_features))]
7+
#![cfg_attr(min, feature(min_const_generics))]
8+
#![warn(unused_braces)]
9+
10+
11+
struct A<const N: usize>;
12+
13+
fn main() {
14+
let _: A<7>; // ok
15+
let _: A< 7 >; //~ WARN unnecessary braces
16+
let _: A<{ 3 + 5 }>; // ok
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: unnecessary braces around const expression
2+
--> $DIR/unused_braces.rs:15:14
3+
|
4+
LL | let _: A<{ 7 }>;
5+
| ^^^^^ help: remove these braces
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused_braces.rs:8:9
9+
|
10+
LL | #![warn(unused_braces)]
11+
| ^^^^^^^^^^^^^
12+
13+
warning: 1 warning emitted
14+

src/test/ui/const-generics/unused_braces.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// check-pass
22
// run-rustfix
3+
// revisions: full min
34

4-
#![allow(incomplete_features)]
5+
#![cfg_attr(full, feature(const_generics))]
6+
#![cfg_attr(full, allow(incomplete_features))]
7+
#![cfg_attr(min, feature(min_const_generics))]
58
#![warn(unused_braces)]
69

7-
#![feature(const_generics)]
810

911
struct A<const N: usize>;
1012

0 commit comments

Comments
 (0)