Skip to content

Commit 26d4291

Browse files
Add ui tests
1 parent f40881d commit 26d4291

7 files changed

Lines changed: 612 additions & 0 deletions

tests/ui/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,11 @@ This test category revolves around trait objects with `Sized` having illegal ope
699699

700700
Tests on lifetime elision in impl function signatures. See [Lifetime elision | Nomicon](https://doc.rust-lang.org/nomicon/lifetime-elision.html).
701701

702+
## `tests/ui/impl-restriction/`
703+
Tests for `#![feature(impl_restriction)]`. See [Tracking issue for restrictions #105077
704+
](https://github.com/rust-lang/rust/issues/105077).
705+
706+
702707
## `tests/ui/impl-trait/`
703708

704709
Tests for trait impls.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ compile-flags: --crate-type=lib
2+
//@ revisions: with_gate without_gate
3+
//@[with_gate] check-pass
4+
5+
#![cfg_attr(with_gate, feature(impl_restriction))]
6+
#![cfg_attr(with_gate, allow(incomplete_features))]
7+
#![feature(auto_traits, const_trait_impl)]
8+
9+
pub impl(crate) trait Bar {} //[without_gate]~ ERROR `impl` restrictions are experimental
10+
pub impl(in crate) trait BarInCrate {} //[without_gate]~ ERROR `impl` restrictions are experimental
11+
12+
mod foo {
13+
pub impl(in crate::foo) trait Baz {} //[without_gate]~ ERROR `impl` restrictions are experimental
14+
pub unsafe impl(super) trait BazUnsafeSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
15+
pub auto impl(self) trait BazAutoSelf {} //[without_gate]~ ERROR `impl` restrictions are experimental
16+
pub const impl(in self) trait BazConst {} //[without_gate]~ ERROR `impl` restrictions are experimental
17+
18+
mod foo_inner {
19+
pub impl(in crate::foo::foo_inner) trait Qux {} //[without_gate]~ ERROR `impl` restrictions are experimental
20+
pub unsafe auto impl(in crate::foo::foo_inner) trait QuxAutoUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
21+
pub const unsafe impl(in crate::foo::foo_inner) trait QuxConstUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
22+
}
23+
24+
#[cfg(false)]
25+
pub impl(crate) trait Bar {} //[without_gate]~ ERROR `impl` restrictions are experimental
26+
#[cfg(false)]
27+
pub impl(in crate) trait BarInCrate {} //[without_gate]~ ERROR `impl` restrictions are experimental
28+
#[cfg(false)]
29+
pub unsafe impl(self) trait BazUnsafeSelf {} //[without_gate]~ ERROR `impl` restrictions are experimental
30+
#[cfg(false)]
31+
pub auto impl(in super) trait BazAutoSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
32+
#[cfg(false)]
33+
pub const impl(super) trait BazConstSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
34+
35+
#[cfg(false)]
36+
mod cfged_out_foo {
37+
pub impl(in crate::foo::cfged_out_foo) trait CfgedOutQux {} //[without_gate]~ ERROR `impl` restrictions are experimental
38+
pub unsafe auto impl(in crate::foo::cfged_out_foo) trait CfgedOutQuxUnsafeAuto {} //[without_gate]~ ERROR `impl` restrictions are experimental
39+
pub const unsafe impl(in crate::foo::cfged_out_foo) trait CfgedOutQuxConstUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
40+
}
41+
42+
// auto traits cannot be const, so we do not include these combinations in the test.
43+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
error[E0658]: `impl` restrictions are experimental
2+
--> $DIR/feature-gate-impl-restriction.rs:9:5
3+
|
4+
LL | pub impl(crate) trait Bar {}
5+
| ^^^^^^^^^^^
6+
|
7+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
8+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0658]: `impl` restrictions are experimental
12+
--> $DIR/feature-gate-impl-restriction.rs:10:5
13+
|
14+
LL | pub impl(in crate) trait BarInCrate {}
15+
| ^^^^^^^^^^^^^^
16+
|
17+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
18+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error[E0658]: `impl` restrictions are experimental
22+
--> $DIR/feature-gate-impl-restriction.rs:13:9
23+
|
24+
LL | pub impl(in crate::foo) trait Baz {}
25+
| ^^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
28+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: `impl` restrictions are experimental
32+
--> $DIR/feature-gate-impl-restriction.rs:14:16
33+
|
34+
LL | pub unsafe impl(super) trait BazUnsafeSuper {}
35+
| ^^^^^^^^^^^
36+
|
37+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
38+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
41+
error[E0658]: `impl` restrictions are experimental
42+
--> $DIR/feature-gate-impl-restriction.rs:15:14
43+
|
44+
LL | pub auto impl(self) trait BazAutoSelf {}
45+
| ^^^^^^^^^^
46+
|
47+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
48+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
49+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
50+
51+
error[E0658]: `impl` restrictions are experimental
52+
--> $DIR/feature-gate-impl-restriction.rs:16:15
53+
|
54+
LL | pub const impl(in self) trait BazConst {}
55+
| ^^^^^^^^^^^^^
56+
|
57+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
58+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
59+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
60+
61+
error[E0658]: `impl` restrictions are experimental
62+
--> $DIR/feature-gate-impl-restriction.rs:19:13
63+
|
64+
LL | pub impl(in crate::foo::foo_inner) trait Qux {}
65+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
|
67+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
68+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
69+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
70+
71+
error[E0658]: `impl` restrictions are experimental
72+
--> $DIR/feature-gate-impl-restriction.rs:20:25
73+
|
74+
LL | ... pub unsafe auto impl(in crate::foo::foo_inner) trait QuxAutoUnsafe {}
75+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76+
|
77+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
78+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
79+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
80+
81+
error[E0658]: `impl` restrictions are experimental
82+
--> $DIR/feature-gate-impl-restriction.rs:21:26
83+
|
84+
LL | ... pub const unsafe impl(in crate::foo::foo_inner) trait QuxConstUnsafe {}
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86+
|
87+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
88+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
89+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
90+
91+
error[E0658]: `impl` restrictions are experimental
92+
--> $DIR/feature-gate-impl-restriction.rs:25:9
93+
|
94+
LL | pub impl(crate) trait Bar {}
95+
| ^^^^^^^^^^^
96+
|
97+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
98+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
99+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
100+
101+
error[E0658]: `impl` restrictions are experimental
102+
--> $DIR/feature-gate-impl-restriction.rs:27:9
103+
|
104+
LL | pub impl(in crate) trait BarInCrate {}
105+
| ^^^^^^^^^^^^^^
106+
|
107+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
108+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
109+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
110+
111+
error[E0658]: `impl` restrictions are experimental
112+
--> $DIR/feature-gate-impl-restriction.rs:29:16
113+
|
114+
LL | pub unsafe impl(self) trait BazUnsafeSelf {}
115+
| ^^^^^^^^^^
116+
|
117+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
118+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
119+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
120+
121+
error[E0658]: `impl` restrictions are experimental
122+
--> $DIR/feature-gate-impl-restriction.rs:31:14
123+
|
124+
LL | pub auto impl(in super) trait BazAutoSuper {}
125+
| ^^^^^^^^^^^^^^
126+
|
127+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
128+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
129+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
130+
131+
error[E0658]: `impl` restrictions are experimental
132+
--> $DIR/feature-gate-impl-restriction.rs:33:15
133+
|
134+
LL | pub const impl(super) trait BazConstSuper {}
135+
| ^^^^^^^^^^^
136+
|
137+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
138+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
139+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
140+
141+
error[E0658]: `impl` restrictions are experimental
142+
--> $DIR/feature-gate-impl-restriction.rs:37:13
143+
|
144+
LL | pub impl(in crate::foo::cfged_out_foo) trait CfgedOutQux {}
145+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146+
|
147+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
148+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
149+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
150+
151+
error[E0658]: `impl` restrictions are experimental
152+
--> $DIR/feature-gate-impl-restriction.rs:38:25
153+
|
154+
LL | ... pub unsafe auto impl(in crate::foo::cfged_out_foo) trait CfgedOutQuxUnsafeAuto {}
155+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156+
|
157+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
158+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
159+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
160+
161+
error[E0658]: `impl` restrictions are experimental
162+
--> $DIR/feature-gate-impl-restriction.rs:39:26
163+
|
164+
LL | ... pub const unsafe impl(in crate::foo::cfged_out_foo) trait CfgedOutQuxConstUnsafe {}
165+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
166+
|
167+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
168+
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
169+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
170+
171+
error: aborting due to 17 previous errors
172+
173+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: --crate-type=lib
2+
//@ revisions: with_gate without_gate
3+
#![cfg_attr(with_gate, feature(impl_restriction))]
4+
//[with_gate]~^ WARN the feature `impl_restriction` is incomplete and may not be safe to use and/or cause compiler crashes
5+
#![feature(auto_traits, const_trait_impl)]
6+
7+
mod foo {
8+
pub impl(crate::foo) trait Baz {} //~ ERROR incorrect `impl` restriction
9+
//[without_gate]~^ ERROR `impl` restrictions are experimental
10+
pub unsafe impl(crate::foo) trait BazUnsafe {} //~ ERROR incorrect `impl` restriction
11+
//[without_gate]~^ ERROR `impl` restrictions are experimental
12+
pub auto impl(crate::foo) trait BazAuto {} //~ ERROR incorrect `impl` restriction
13+
//[without_gate]~^ ERROR `impl` restrictions are experimental
14+
pub const impl(crate::foo) trait BazConst {} //~ ERROR incorrect `impl` restriction
15+
//[without_gate]~^ ERROR `impl` restrictions are experimental
16+
pub const unsafe impl(crate::foo) trait BazConstUnsafe {} //~ ERROR incorrect `impl` restriction
17+
//[without_gate]~^ ERROR `impl` restrictions are experimental
18+
pub unsafe auto impl(crate::foo) trait BazUnsafeAuto {} //~ ERROR incorrect `impl` restriction
19+
//[without_gate]~^ ERROR `impl` restrictions are experimental
20+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
error: incorrect `impl` restriction
2+
--> $DIR/recover-incorrect-impl-restriction.rs:8:14
3+
|
4+
LL | pub impl(crate::foo) trait Baz {}
5+
| ^^^^^^^^^^
6+
|
7+
= help: some possible `impl` restrictions are:
8+
`impl(crate)`: can only be implemented in the current crate
9+
`impl(super)`: can only be implemented in the parent module
10+
`impl(self)`: can only be implemented in current module
11+
`impl(in path::to::module)`: can only be implemented in the specified path
12+
help: help: use `in` to restrict implementations to the path `crate::foo`
13+
|
14+
LL | pub impl(in crate::foo) trait Baz {}
15+
| ++
16+
17+
error: incorrect `impl` restriction
18+
--> $DIR/recover-incorrect-impl-restriction.rs:10:21
19+
|
20+
LL | pub unsafe impl(crate::foo) trait BazUnsafe {}
21+
| ^^^^^^^^^^
22+
|
23+
= help: some possible `impl` restrictions are:
24+
`impl(crate)`: can only be implemented in the current crate
25+
`impl(super)`: can only be implemented in the parent module
26+
`impl(self)`: can only be implemented in current module
27+
`impl(in path::to::module)`: can only be implemented in the specified path
28+
help: help: use `in` to restrict implementations to the path `crate::foo`
29+
|
30+
LL | pub unsafe impl(in crate::foo) trait BazUnsafe {}
31+
| ++
32+
33+
error: incorrect `impl` restriction
34+
--> $DIR/recover-incorrect-impl-restriction.rs:12:19
35+
|
36+
LL | pub auto impl(crate::foo) trait BazAuto {}
37+
| ^^^^^^^^^^
38+
|
39+
= help: some possible `impl` restrictions are:
40+
`impl(crate)`: can only be implemented in the current crate
41+
`impl(super)`: can only be implemented in the parent module
42+
`impl(self)`: can only be implemented in current module
43+
`impl(in path::to::module)`: can only be implemented in the specified path
44+
help: help: use `in` to restrict implementations to the path `crate::foo`
45+
|
46+
LL | pub auto impl(in crate::foo) trait BazAuto {}
47+
| ++
48+
49+
error: incorrect `impl` restriction
50+
--> $DIR/recover-incorrect-impl-restriction.rs:14:20
51+
|
52+
LL | pub const impl(crate::foo) trait BazConst {}
53+
| ^^^^^^^^^^
54+
|
55+
= help: some possible `impl` restrictions are:
56+
`impl(crate)`: can only be implemented in the current crate
57+
`impl(super)`: can only be implemented in the parent module
58+
`impl(self)`: can only be implemented in current module
59+
`impl(in path::to::module)`: can only be implemented in the specified path
60+
help: help: use `in` to restrict implementations to the path `crate::foo`
61+
|
62+
LL | pub const impl(in crate::foo) trait BazConst {}
63+
| ++
64+
65+
error: incorrect `impl` restriction
66+
--> $DIR/recover-incorrect-impl-restriction.rs:16:27
67+
|
68+
LL | pub const unsafe impl(crate::foo) trait BazConstUnsafe {}
69+
| ^^^^^^^^^^
70+
|
71+
= help: some possible `impl` restrictions are:
72+
`impl(crate)`: can only be implemented in the current crate
73+
`impl(super)`: can only be implemented in the parent module
74+
`impl(self)`: can only be implemented in current module
75+
`impl(in path::to::module)`: can only be implemented in the specified path
76+
help: help: use `in` to restrict implementations to the path `crate::foo`
77+
|
78+
LL | pub const unsafe impl(in crate::foo) trait BazConstUnsafe {}
79+
| ++
80+
81+
error: incorrect `impl` restriction
82+
--> $DIR/recover-incorrect-impl-restriction.rs:18:26
83+
|
84+
LL | pub unsafe auto impl(crate::foo) trait BazUnsafeAuto {}
85+
| ^^^^^^^^^^
86+
|
87+
= help: some possible `impl` restrictions are:
88+
`impl(crate)`: can only be implemented in the current crate
89+
`impl(super)`: can only be implemented in the parent module
90+
`impl(self)`: can only be implemented in current module
91+
`impl(in path::to::module)`: can only be implemented in the specified path
92+
help: help: use `in` to restrict implementations to the path `crate::foo`
93+
|
94+
LL | pub unsafe auto impl(in crate::foo) trait BazUnsafeAuto {}
95+
| ++
96+
97+
warning: the feature `impl_restriction` is incomplete and may not be safe to use and/or cause compiler crashes
98+
--> $DIR/recover-incorrect-impl-restriction.rs:3:32
99+
|
100+
LL | #![cfg_attr(with_gate, feature(impl_restriction))]
101+
| ^^^^^^^^^^^^^^^^
102+
|
103+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
104+
= note: `#[warn(incomplete_features)]` on by default
105+
106+
error: aborting due to 6 previous errors; 1 warning emitted
107+

0 commit comments

Comments
 (0)