Skip to content

Commit

Permalink
Add tests for RFC 2632
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Jan 5, 2020
1 parent 5d43134 commit 14c9ab8
Show file tree
Hide file tree
Showing 24 changed files with 333 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/test/ui/parser/bounds-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
8 changes: 7 additions & 1 deletion src/test/ui/parser/bounds-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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 `>`
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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>,
>;
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs
Original file line number Diff line number Diff line change
@@ -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() {}
18 changes: 18 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/inherent-impl.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/syntax.rs
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 14c9ab8

Please sign in to comment.