Skip to content

Commit 14c9ab8

Browse files
Add tests for RFC 2632
1 parent 5d43134 commit 14c9ab8

24 files changed

+333
-1
lines changed

src/test/ui/parser/bounds-type.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ struct S<
88
T: ?for<'a> Trait, // OK
99
T: Tr +, // OK
1010
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
11+
12+
T: ?const Tr, // OK
13+
T: ?const ?Tr, // OK
14+
T: ?const Tr + 'a, // OK
15+
T: ?const 'a, //~ ERROR `?const` may only modify trait bounds, not lifetime bounds
1116
>;
1217

1318
fn main() {}

src/test/ui/parser/bounds-type.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ error: `?` may only modify trait bounds, not lifetime bounds
44
LL | T: ?'a,
55
| ^
66

7-
error: aborting due to previous error
7+
error: `?const` may only modify trait bounds, not lifetime bounds
8+
--> $DIR/bounds-type.rs:15:8
9+
|
10+
LL | T: ?const 'a,
11+
| ^^^^^^
12+
13+
error: aborting due to 2 previous errors
814

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: `?const` on trait bounds is not yet implemented
2+
--> $DIR/feature-gate.rs:11:29
3+
|
4+
LL | const fn get_assoc_const<S: ?const T>() -> i32 { <S as T>::CONST }
5+
| ^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// revisions: stock gated
2+
// gate-test-const_trait_bound_opt_out
3+
4+
#![cfg_attr(gated, feature(const_trait_bound_opt_out))]
5+
#![allow(incomplete_features)]
6+
7+
trait T {
8+
const CONST: i32;
9+
}
10+
11+
const fn get_assoc_const<S: ?const T>() -> i32 { <S as T>::CONST }
12+
//[stock]~^ ERROR `?const` on trait bounds is experimental
13+
//[stock,gated]~^^ ERROR `?const` on trait bounds is not yet implemented
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0658]: `?const` on trait bounds is experimental
2+
--> $DIR/feature-gate.rs:11:29
3+
|
4+
LL | const fn get_assoc_const<S: ?const T>() -> i32 { <S as T>::CONST }
5+
| ^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/67794
8+
= help: add `#![feature(const_trait_bound_opt_out)]` to the crate attributes to enable
9+
10+
error: `?const` on trait bounds is not yet implemented
11+
--> $DIR/feature-gate.rs:11:29
12+
|
13+
LL | const fn get_assoc_const<S: ?const T>() -> i32 { <S as T>::CONST }
14+
| ^^^^^^^^
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(const_trait_bound_opt_out)]
2+
#![feature(associated_type_bounds)]
3+
#![allow(incomplete_features)]
4+
5+
trait T {}
6+
struct S;
7+
impl T for S {}
8+
9+
fn rpit() -> impl ?const T { S }
10+
//~^ ERROR `?const` is not permitted in `impl Trait`
11+
//~| ERROR `?const` on trait bounds is not yet implemented
12+
13+
fn apit(_: impl ?const T) {}
14+
//~^ ERROR `?const` is not permitted in `impl Trait`
15+
//~| ERROR `?const` on trait bounds is not yet implemented
16+
17+
fn rpit_assoc_bound() -> impl IntoIterator<Item: ?const T> { Some(S) }
18+
//~^ ERROR `?const` is not permitted in `impl Trait`
19+
//~| ERROR `?const` on trait bounds is not yet implemented
20+
21+
fn apit_assoc_bound(_: impl IntoIterator<Item: ?const T>) {}
22+
//~^ ERROR `?const` is not permitted in `impl Trait`
23+
//~| ERROR `?const` on trait bounds is not yet implemented
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error: `?const` is not permitted in `impl Trait`
2+
--> $DIR/in-impl-trait.rs:9:19
3+
|
4+
LL | fn rpit() -> impl ?const T { S }
5+
| ^^^^^^^^
6+
7+
error: `?const` is not permitted in `impl Trait`
8+
--> $DIR/in-impl-trait.rs:13:17
9+
|
10+
LL | fn apit(_: impl ?const T) {}
11+
| ^^^^^^^^
12+
13+
error: `?const` is not permitted in `impl Trait`
14+
--> $DIR/in-impl-trait.rs:17:50
15+
|
16+
LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ?const T> { Some(S) }
17+
| ^^^^^^^^
18+
19+
error: `?const` is not permitted in `impl Trait`
20+
--> $DIR/in-impl-trait.rs:21:48
21+
|
22+
LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ?const T>) {}
23+
| ^^^^^^^^
24+
25+
error: `?const` on trait bounds is not yet implemented
26+
--> $DIR/in-impl-trait.rs:9:19
27+
|
28+
LL | fn rpit() -> impl ?const T { S }
29+
| ^^^^^^^^
30+
31+
error: `?const` on trait bounds is not yet implemented
32+
--> $DIR/in-impl-trait.rs:13:17
33+
|
34+
LL | fn apit(_: impl ?const T) {}
35+
| ^^^^^^^^
36+
37+
error: `?const` on trait bounds is not yet implemented
38+
--> $DIR/in-impl-trait.rs:17:50
39+
|
40+
LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ?const T> { Some(S) }
41+
| ^^^^^^^^
42+
43+
error: `?const` on trait bounds is not yet implemented
44+
--> $DIR/in-impl-trait.rs:21:48
45+
|
46+
LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ?const T>) {}
47+
| ^^^^^^^^
48+
49+
error: aborting due to 8 previous errors
50+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(const_trait_bound_opt_out)]
2+
#![allow(incomplete_features)]
3+
4+
trait Super {}
5+
trait T: ?const Super {}
6+
//~^ ERROR `?const` is not permitted in supertraits
7+
//~| ERROR `?const` on trait bounds is not yet implemented
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: `?const` is not permitted in supertraits
2+
--> $DIR/in-trait-bounds.rs:5:10
3+
|
4+
LL | trait T: ?const Super {}
5+
| ^^^^^^^^^^^^
6+
7+
error: `?const` on trait bounds is not yet implemented
8+
--> $DIR/in-trait-bounds.rs:5:10
9+
|
10+
LL | trait T: ?const Super {}
11+
| ^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(const_trait_bound_opt_out)]
2+
#![allow(bare_trait_objects)]
3+
#![allow(incomplete_features)]
4+
5+
struct S;
6+
trait T {}
7+
impl T for S {}
8+
9+
// An inherent impl for the trait object `?const T`.
10+
impl ?const T {}
11+
//~^ ERROR `?const` is not permitted in trait objects
12+
//~| ERROR `?const` on trait bounds is not yet implemented
13+
14+
fn trait_object() -> &'static dyn ?const T { &S }
15+
//~^ ERROR `?const` is not permitted in trait objects
16+
//~| ERROR `?const` on trait bounds is not yet implemented
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: `?const` is not permitted in trait objects
2+
--> $DIR/in-trait-object.rs:10:6
3+
|
4+
LL | impl ?const T {}
5+
| ^^^^^^^^
6+
7+
error: `?const` is not permitted in trait objects
8+
--> $DIR/in-trait-object.rs:14:35
9+
|
10+
LL | fn trait_object() -> &'static dyn ?const T { &S }
11+
| ^^^^^^^^
12+
13+
error: `?const` on trait bounds is not yet implemented
14+
--> $DIR/in-trait-object.rs:10:6
15+
|
16+
LL | impl ?const T {}
17+
| ^^^^^^^^
18+
19+
error: `?const` on trait bounds is not yet implemented
20+
--> $DIR/in-trait-object.rs:14:35
21+
|
22+
LL | fn trait_object() -> &'static dyn ?const T { &S }
23+
| ^^^^^^^^
24+
25+
error: aborting due to 4 previous errors
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: -Z parse-only
2+
3+
#![feature(const_trait_bound_opt_out)]
4+
#![allow(incomplete_features)]
5+
6+
struct S<T: ?const ?const Tr>;
7+
//~^ ERROR expected identifier, found keyword `const`
8+
//~| ERROR expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: expected identifier, found keyword `const`
2+
--> $DIR/opt-out-twice.rs:6:21
3+
|
4+
LL | struct S<T: ?const ?const Tr>;
5+
| ^^^^^ expected identifier, found keyword
6+
7+
error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
8+
--> $DIR/opt-out-twice.rs:6:27
9+
|
10+
LL | struct S<T: ?const ?const Tr>;
11+
| ^^ expected one of 7 possible tokens
12+
13+
error: aborting due to 2 previous errors
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -Z parse-only
2+
// check-pass
3+
4+
#![feature(const_trait_bound_opt_out)]
5+
#![allow(incomplete_features)]
6+
7+
struct S<
8+
T: ?const ?for<'a> Tr<'a> + 'static + ?const std::ops::Add,
9+
T: ?const ?for<'a: 'b> m::Trait<'a>,
10+
>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: -Z parse-only
2+
3+
#![feature(const_trait_bound_opt_out)]
4+
#![allow(incomplete_features)]
5+
6+
struct S<T: const Tr>;
7+
//~^ ERROR expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, lifetime, or path
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, lifetime, or path, found keyword `const`
2+
--> $DIR/without-question-mark.rs:6:13
3+
|
4+
LL | struct S<T: const Tr>;
5+
| ^^^^^ expected one of 9 possible tokens
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: const trait impls are not yet implemented
2+
--> $DIR/feature-gate.rs:9:1
3+
|
4+
LL | impl const T for S {}
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// revisions: stock gated
2+
// gate-test-const_trait_impl
3+
4+
#![cfg_attr(gated, feature(const_trait_impl))]
5+
#![allow(incomplete_features)]
6+
7+
struct S;
8+
trait T {}
9+
impl const T for S {}
10+
//[stock]~^ ERROR const trait impls are experimental
11+
//[stock,gated]~^^ ERROR const trait impls are not yet implemented
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0658]: const trait impls are experimental
2+
--> $DIR/feature-gate.rs:9:6
3+
|
4+
LL | impl const T for S {}
5+
| ^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/67792
8+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
9+
10+
error: const trait impls are not yet implemented
11+
--> $DIR/feature-gate.rs:9:1
12+
|
13+
LL | impl const T for S {}
14+
| ^^^^^^^^^^^^^^^^^^^^^
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_trait_bound_opt_out)]
2+
#![feature(const_trait_impl)]
3+
#![allow(incomplete_features)]
4+
5+
struct S;
6+
trait T {}
7+
8+
impl ?const T for S {}
9+
//~^ ERROR expected a trait, found type
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected a trait, found type
2+
--> $DIR/impl-opt-out-trait.rs:8:6
3+
|
4+
LL | impl ?const T for S {}
5+
| ^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile-flags: -Z parse-only
2+
3+
#![feature(const_trait_impl)]
4+
#![feature(const_trait_bound_opt_out)]
5+
#![allow(incomplete_features)]
6+
#![allow(bare_trait_objects)]
7+
8+
struct S;
9+
trait T {}
10+
11+
impl const T {}
12+
//~^ ERROR `const` cannot modify an inherent impl
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: `const` cannot modify an inherent impl
2+
--> $DIR/inherent-impl.rs:11:6
3+
|
4+
LL | impl const T {}
5+
| ^^^^^
6+
|
7+
= help: only a trait impl can be `const`
8+
9+
error: aborting due to previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-flags: -Z parse-only
2+
// check-pass
3+
4+
#![feature(const_trait_bound_opt_out)]
5+
#![feature(const_trait_impl)]
6+
#![allow(incomplete_features)]
7+
8+
// For now, this parses since an error does not occur until AST lowering.
9+
impl ?const T {}

0 commit comments

Comments
 (0)