Add tests for RFC 2632
This commit is contained in:
parent
d843e002bb
commit
343e1570a9
24 changed files with 333 additions and 1 deletions
|
@ -8,6 +8,11 @@ struct S<
|
|||
T: ?for<'a> Trait, // OK
|
||||
T: Tr +, // OK
|
||||
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
|
||||
|
||||
T: ?const Tr, // OK
|
||||
T: ?const ?Tr, // OK
|
||||
T: ?const Tr + 'a, // OK
|
||||
T: ?const 'a, //~ ERROR `?const` may only modify trait bounds, not lifetime bounds
|
||||
>;
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -4,5 +4,11 @@ error: `?` may only modify trait bounds, not lifetime bounds
|
|||
LL | T: ?'a,
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: `?const` may only modify trait bounds, not lifetime bounds
|
||||
--> $DIR/bounds-type.rs:15:8
|
||||
|
|
||||
LL | T: ?const 'a,
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/feature-gate.rs:11:29
|
||||
|
|
||||
LL | const fn get_assoc_const<S: ?const T>() -> i32 { <S as T>::CONST }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
// revisions: stock gated
|
||||
// gate-test-const_trait_bound_opt_out
|
||||
|
||||
#![cfg_attr(gated, feature(const_trait_bound_opt_out))]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait T {
|
||||
const CONST: i32;
|
||||
}
|
||||
|
||||
const fn get_assoc_const<S: ?const T>() -> i32 { <S as T>::CONST }
|
||||
//[stock]~^ ERROR `?const` on trait bounds is experimental
|
||||
//[stock,gated]~^^ ERROR `?const` on trait bounds is not yet implemented
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,18 @@
|
|||
error[E0658]: `?const` on trait bounds is experimental
|
||||
--> $DIR/feature-gate.rs:11:29
|
||||
|
|
||||
LL | const fn get_assoc_const<S: ?const T>() -> i32 { <S as T>::CONST }
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: for more information, see https://github.com/rust-lang/rust/issues/67794
|
||||
= help: add `#![feature(const_trait_bound_opt_out)]` to the crate attributes to enable
|
||||
|
||||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/feature-gate.rs:11:29
|
||||
|
|
||||
LL | const fn get_assoc_const<S: ?const T>() -> i32 { <S as T>::CONST }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -0,0 +1,25 @@
|
|||
#![feature(const_trait_bound_opt_out)]
|
||||
#![feature(associated_type_bounds)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait T {}
|
||||
struct S;
|
||||
impl T for S {}
|
||||
|
||||
fn rpit() -> impl ?const T { S }
|
||||
//~^ ERROR `?const` is not permitted in `impl Trait`
|
||||
//~| ERROR `?const` on trait bounds is not yet implemented
|
||||
|
||||
fn apit(_: impl ?const T) {}
|
||||
//~^ ERROR `?const` is not permitted in `impl Trait`
|
||||
//~| ERROR `?const` on trait bounds is not yet implemented
|
||||
|
||||
fn rpit_assoc_bound() -> impl IntoIterator<Item: ?const T> { Some(S) }
|
||||
//~^ ERROR `?const` is not permitted in `impl Trait`
|
||||
//~| ERROR `?const` on trait bounds is not yet implemented
|
||||
|
||||
fn apit_assoc_bound(_: impl IntoIterator<Item: ?const T>) {}
|
||||
//~^ ERROR `?const` is not permitted in `impl Trait`
|
||||
//~| ERROR `?const` on trait bounds is not yet implemented
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,50 @@
|
|||
error: `?const` is not permitted in `impl Trait`
|
||||
--> $DIR/in-impl-trait.rs:9:19
|
||||
|
|
||||
LL | fn rpit() -> impl ?const T { S }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` is not permitted in `impl Trait`
|
||||
--> $DIR/in-impl-trait.rs:13:17
|
||||
|
|
||||
LL | fn apit(_: impl ?const T) {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` is not permitted in `impl Trait`
|
||||
--> $DIR/in-impl-trait.rs:17:50
|
||||
|
|
||||
LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ?const T> { Some(S) }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` is not permitted in `impl Trait`
|
||||
--> $DIR/in-impl-trait.rs:21:48
|
||||
|
|
||||
LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ?const T>) {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/in-impl-trait.rs:9:19
|
||||
|
|
||||
LL | fn rpit() -> impl ?const T { S }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/in-impl-trait.rs:13:17
|
||||
|
|
||||
LL | fn apit(_: impl ?const T) {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/in-impl-trait.rs:17:50
|
||||
|
|
||||
LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ?const T> { Some(S) }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/in-impl-trait.rs:21:48
|
||||
|
|
||||
LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ?const T>) {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#![feature(const_trait_bound_opt_out)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait Super {}
|
||||
trait T: ?const Super {}
|
||||
//~^ ERROR `?const` is not permitted in supertraits
|
||||
//~| ERROR `?const` on trait bounds is not yet implemented
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,14 @@
|
|||
error: `?const` is not permitted in supertraits
|
||||
--> $DIR/in-trait-bounds.rs:5:10
|
||||
|
|
||||
LL | trait T: ?const Super {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/in-trait-bounds.rs:5:10
|
||||
|
|
||||
LL | trait T: ?const Super {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#![feature(const_trait_bound_opt_out)]
|
||||
#![allow(bare_trait_objects)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct S;
|
||||
trait T {}
|
||||
impl T for S {}
|
||||
|
||||
// An inherent impl for the trait object `?const T`.
|
||||
impl ?const T {}
|
||||
//~^ ERROR `?const` is not permitted in trait objects
|
||||
//~| ERROR `?const` on trait bounds is not yet implemented
|
||||
|
||||
fn trait_object() -> &'static dyn ?const T { &S }
|
||||
//~^ ERROR `?const` is not permitted in trait objects
|
||||
//~| ERROR `?const` on trait bounds is not yet implemented
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,26 @@
|
|||
error: `?const` is not permitted in trait objects
|
||||
--> $DIR/in-trait-object.rs:10:6
|
||||
|
|
||||
LL | impl ?const T {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` is not permitted in trait objects
|
||||
--> $DIR/in-trait-object.rs:14:35
|
||||
|
|
||||
LL | fn trait_object() -> &'static dyn ?const T { &S }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/in-trait-object.rs:10:6
|
||||
|
|
||||
LL | impl ?const T {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?const` on trait bounds is not yet implemented
|
||||
--> $DIR/in-trait-object.rs:14:35
|
||||
|
|
||||
LL | fn trait_object() -> &'static dyn ?const T { &S }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// compile-flags: -Z parse-only
|
||||
|
||||
#![feature(const_trait_bound_opt_out)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct S<T: ?const ?const Tr>;
|
||||
//~^ ERROR expected identifier, found keyword `const`
|
||||
//~| ERROR expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`
|
|
@ -0,0 +1,14 @@
|
|||
error: expected identifier, found keyword `const`
|
||||
--> $DIR/opt-out-twice.rs:6:21
|
||||
|
|
||||
LL | struct S<T: ?const ?const Tr>;
|
||||
| ^^^^^ expected identifier, found keyword
|
||||
|
||||
error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
|
||||
--> $DIR/opt-out-twice.rs:6:27
|
||||
|
|
||||
LL | struct S<T: ?const ?const Tr>;
|
||||
| ^^ expected one of 7 possible tokens
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
// compile-flags: -Z parse-only
|
||||
// check-pass
|
||||
|
||||
#![feature(const_trait_bound_opt_out)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct S<
|
||||
T: ?const ?for<'a> Tr<'a> + 'static + ?const std::ops::Add,
|
||||
T: ?const ?for<'a: 'b> m::Trait<'a>,
|
||||
>;
|
|
@ -0,0 +1,7 @@
|
|||
// compile-flags: -Z parse-only
|
||||
|
||||
#![feature(const_trait_bound_opt_out)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct S<T: const Tr>;
|
||||
//~^ ERROR expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, lifetime, or path
|
|
@ -0,0 +1,8 @@
|
|||
error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, lifetime, or path, found keyword `const`
|
||||
--> $DIR/without-question-mark.rs:6:13
|
||||
|
|
||||
LL | struct S<T: const Tr>;
|
||||
| ^^^^^ expected one of 9 possible tokens
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
error: const trait impls are not yet implemented
|
||||
--> $DIR/feature-gate.rs:9:1
|
||||
|
|
||||
LL | impl const T for S {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
13
src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs
Normal file
13
src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// revisions: stock gated
|
||||
// gate-test-const_trait_impl
|
||||
|
||||
#![cfg_attr(gated, feature(const_trait_impl))]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct S;
|
||||
trait T {}
|
||||
impl const T for S {}
|
||||
//[stock]~^ ERROR const trait impls are experimental
|
||||
//[stock,gated]~^^ ERROR const trait impls are not yet implemented
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,18 @@
|
|||
error[E0658]: const trait impls are experimental
|
||||
--> $DIR/feature-gate.rs:9:6
|
||||
|
|
||||
LL | impl const T for S {}
|
||||
| ^^^^^
|
||||
|
|
||||
= note: for more information, see https://github.com/rust-lang/rust/issues/67792
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error: const trait impls are not yet implemented
|
||||
--> $DIR/feature-gate.rs:9:1
|
||||
|
|
||||
LL | impl const T for S {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
11
src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.rs
Normal file
11
src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
#![feature(const_trait_bound_opt_out)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct S;
|
||||
trait T {}
|
||||
|
||||
impl ?const T for S {}
|
||||
//~^ ERROR expected a trait, found type
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,8 @@
|
|||
error: expected a trait, found type
|
||||
--> $DIR/impl-opt-out-trait.rs:8:6
|
||||
|
|
||||
LL | impl ?const T for S {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
14
src/test/ui/rfc-2632-const-trait-impl/inherent-impl.rs
Normal file
14
src/test/ui/rfc-2632-const-trait-impl/inherent-impl.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// compile-flags: -Z parse-only
|
||||
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(const_trait_bound_opt_out)]
|
||||
#![allow(incomplete_features)]
|
||||
#![allow(bare_trait_objects)]
|
||||
|
||||
struct S;
|
||||
trait T {}
|
||||
|
||||
impl const T {}
|
||||
//~^ ERROR `const` cannot modify an inherent impl
|
||||
|
||||
fn main() {}
|
10
src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr
Normal file
10
src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr
Normal file
|
@ -0,0 +1,10 @@
|
|||
error: `const` cannot modify an inherent impl
|
||||
--> $DIR/inherent-impl.rs:11:6
|
||||
|
|
||||
LL | impl const T {}
|
||||
| ^^^^^
|
||||
|
|
||||
= help: only a trait impl can be `const`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
9
src/test/ui/rfc-2632-const-trait-impl/syntax.rs
Normal file
9
src/test/ui/rfc-2632-const-trait-impl/syntax.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
// compile-flags: -Z parse-only
|
||||
// check-pass
|
||||
|
||||
#![feature(const_trait_bound_opt_out)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
// For now, this parses since an error does not occur until AST lowering.
|
||||
impl ?const T {}
|
Loading…
Add table
Add a link
Reference in a new issue