mirror of https://github.com/rust-lang/rust.git
Add a bunch of revisions
This adds a bunch of revisions to const-generic tests
This commit is contained in:
parent
c94ed5ca91
commit
be650a7ecd
|
@ -0,0 +1,14 @@
|
|||
error: using raw pointers as const generic parameters is forbidden
|
||||
--> $DIR/raw-ptr-const-param-deref.rs:10:23
|
||||
|
|
||||
LL | struct Const<const P: *const u32>;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: using raw pointers as const generic parameters is forbidden
|
||||
--> $DIR/raw-ptr-const-param-deref.rs:12:15
|
||||
|
|
||||
LL | impl<const P: *const u32> Const<P> {
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
error: using raw pointers as const generic parameters is forbidden
|
||||
--> $DIR/raw-ptr-const-param-deref.rs:10:23
|
||||
|
|
||||
LL | struct Const<const P: *const u32>;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= note: more complex types are supported with `#[feature(const_generics)]`
|
||||
|
||||
error: using raw pointers as const generic parameters is forbidden
|
||||
--> $DIR/raw-ptr-const-param-deref.rs:12:15
|
||||
|
|
||||
LL | impl<const P: *const u32> Const<P> {
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= note: more complex types are supported with `#[feature(const_generics)]`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
// Assert that cannot use const generics as ptrs and cannot deref them.
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
const A: u32 = 3;
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
error: using raw pointers as const generic parameters is forbidden
|
||||
--> $DIR/raw-ptr-const-param.rs:7:23
|
||||
|
|
||||
LL | struct Const<const P: *const u32>;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error: using raw pointers as const generic parameters is forbidden
|
||||
--> $DIR/raw-ptr-const-param.rs:7:23
|
||||
|
|
||||
LL | struct Const<const P: *const u32>;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= note: more complex types are supported with `#[feature(const_generics)]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct Const<const P: *const u32>; //~ ERROR: using raw pointers as const generic parameters
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct ConstString<const T: &'static str>;
|
||||
struct ConstBytes<const T: &'static [u8]>;
|
||||
|
|
|
@ -1,12 +1,3 @@
|
|||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/slice-const-param-mismatch.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/slice-const-param-mismatch.rs:9:35
|
||||
|
|
||||
|
@ -40,6 +31,6 @@ LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
|
|||
= note: expected struct `ConstBytes<b"AAA">`
|
||||
found struct `ConstBytes<b"BBB">`
|
||||
|
||||
error: aborting due to 3 previous errors; 1 warning emitted
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
error: using `&'static str` as const generic parameters is forbidden
|
||||
--> $DIR/slice-const-param.rs:8:40
|
||||
|
|
||||
LL | pub fn function_with_str<const STRING: &'static str>() -> &'static str {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= note: more complex types are supported with `#[feature(const_generics)]`
|
||||
|
||||
error: using `&'static [u8]` as const generic parameters is forbidden
|
||||
--> $DIR/slice-const-param.rs:13:41
|
||||
|
|
||||
LL | pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= note: more complex types are supported with `#[feature(const_generics)]`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
// run-pass
|
||||
//[full] run-pass
|
||||
// revisions: min full
|
||||
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
pub fn function_with_str<const STRING: &'static str>() -> &'static str {
|
||||
//[min]~^ ERROR using `&'static str` as const
|
||||
STRING
|
||||
}
|
||||
|
||||
pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
|
||||
//[min]~^ ERROR using `&'static [u8]` as const
|
||||
BYTES
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
error[E0573]: expected type, found const parameter `C`
|
||||
--> $DIR/struct-with-invalid-const-param.rs:8:23
|
||||
|
|
||||
LL | struct S<const C: u8>(C);
|
||||
| ----------------------^--
|
||||
| | |
|
||||
| | help: a struct with a similar name exists: `S`
|
||||
| similarly named struct `S` defined here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
|
@ -0,0 +1,12 @@
|
|||
error[E0573]: expected type, found const parameter `C`
|
||||
--> $DIR/struct-with-invalid-const-param.rs:8:23
|
||||
|
|
||||
LL | struct S<const C: u8>(C);
|
||||
| ----------------------^--
|
||||
| | |
|
||||
| | help: a struct with a similar name exists: `S`
|
||||
| similarly named struct `S` defined here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
|
@ -1,5 +1,9 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
// Checks that a const param cannot be stored in a struct.
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct S<const C: u8>(C); //~ ERROR expected type, found const parameter
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
// check-pass
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(const_generics)]
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct Const<const N: usize>;
|
||||
trait Foo<const N: usize> {}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// run-pass
|
||||
// revisions: full min
|
||||
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// run-pass
|
||||
// revisions: full min
|
||||
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
trait T<const A: usize> {
|
||||
fn l<const N: bool>() -> usize;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
error[E0282]: type annotations needed
|
||||
--> $DIR/uninferred-consts.rs:14:5
|
||||
|
|
||||
LL | Foo.foo();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: unable to infer the value of a const parameter
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
|
@ -0,0 +1,11 @@
|
|||
error[E0282]: type annotations needed
|
||||
--> $DIR/uninferred-consts.rs:14:5
|
||||
|
|
||||
LL | Foo.foo();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: unable to infer the value of a const parameter
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
|
@ -1,5 +1,9 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
// Test if emits error if cannot properly infer constant.
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
// taken from https://github.com/rust-lang/rust/issues/70507#issuecomment-615268893
|
||||
struct Foo;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
error[E0412]: cannot find type `UnknownStruct` in this scope
|
||||
--> $DIR/unknown_adt.rs:10:12
|
||||
|
|
||||
LL | let _: UnknownStruct<7>;
|
||||
| ^^^^^^^^^^^^^ not found in this scope
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0412`.
|
|
@ -0,0 +1,9 @@
|
|||
error[E0412]: cannot find type `UnknownStruct` in this scope
|
||||
--> $DIR/unknown_adt.rs:10:12
|
||||
|
|
||||
LL | let _: UnknownStruct<7>;
|
||||
| ^^^^^^^^^^^^^ not found in this scope
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0412`.
|
|
@ -1,5 +1,10 @@
|
|||
#![feature(const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
// Checks errors when there is an abstract data type.
|
||||
// revisions: full min
|
||||
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
fn main() {
|
||||
let _: UnknownStruct<7>;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// check-pass
|
||||
// revisions: full min
|
||||
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct A<const N: usize>; // ok
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// check-pass
|
||||
// run-rustfix
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
#![warn(unused_braces)]
|
||||
|
||||
|
||||
struct A<const N: usize>;
|
||||
|
||||
fn main() {
|
||||
let _: A<7>; // ok
|
||||
let _: A< 7 >; //~ WARN unnecessary braces
|
||||
let _: A<{ 3 + 5 }>; // ok
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
warning: unnecessary braces around const expression
|
||||
--> $DIR/unused_braces.rs:15:14
|
||||
|
|
||||
LL | let _: A<{ 7 }>;
|
||||
| ^^^^^ help: remove these braces
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused_braces.rs:8:9
|
||||
|
|
||||
LL | #![warn(unused_braces)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// check-pass
|
||||
// run-rustfix
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
#![warn(unused_braces)]
|
||||
|
||||
|
||||
struct A<const N: usize>;
|
||||
|
||||
fn main() {
|
||||
let _: A<7>; // ok
|
||||
let _: A< 7 >; //~ WARN unnecessary braces
|
||||
let _: A<{ 3 + 5 }>; // ok
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
warning: unnecessary braces around const expression
|
||||
--> $DIR/unused_braces.rs:15:14
|
||||
|
|
||||
LL | let _: A<{ 7 }>;
|
||||
| ^^^^^ help: remove these braces
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused_braces.rs:8:9
|
||||
|
|
||||
LL | #![warn(unused_braces)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
// check-pass
|
||||
// run-rustfix
|
||||
// revisions: full min
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
#![warn(unused_braces)]
|
||||
|
||||
#![feature(const_generics)]
|
||||
|
||||
struct A<const N: usize>;
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/wf-misc.rs:9:12
|
||||
|
|
||||
LL | let _: [u8; N + 1];
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/wf-misc.rs:17:12
|
||||
|
|
||||
LL | let _: Const::<{N + 1}>;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
error: generic parameters must not be used inside of non trivial constant values
|
||||
--> $DIR/wf-misc.rs:9:17
|
||||
|
|
||||
LL | let _: [u8; N + 1];
|
||||
| ^ 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
|
||||
--> $DIR/wf-misc.rs:17:21
|
||||
|
|
||||
LL | let _: Const::<{N + 1}>;
|
||||
| ^ 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: aborting due to 2 previous errors
|
||||
|
|
@ -1,16 +1,22 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
// Tests miscellaneous well-formedness examples.
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
pub fn arr_len<const N: usize>() {
|
||||
let _: [u8; N + 1];
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non trivial
|
||||
}
|
||||
|
||||
struct Const<const N: usize>;
|
||||
|
||||
pub fn func_call<const N: usize>() {
|
||||
let _: Const::<{N + 1}>;
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non trivial
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
Loading…
Reference in New Issue