Skip to content

Commit 7d71945

Browse files
Add ui tests for incorrect impl restriction recovery
1 parent f26806a commit 7d71945

3 files changed

Lines changed: 242 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 BazUnsafeSuper {} //~ ERROR incorrect `impl` restriction
11+
//[without_gate]~^ ERROR `impl` restrictions are experimental
12+
pub auto impl(crate::foo) trait BazAutoSelf {} //~ 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+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 BazUnsafeSuper {}
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 BazUnsafeSuper {}
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 BazAutoSelf {}
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 BazAutoSelf {}
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+
warning: the feature `impl_restriction` is incomplete and may not be safe to use and/or cause compiler crashes
82+
--> $DIR/recover-incorrect-impl-restriction.rs:3:32
83+
|
84+
LL | #![cfg_attr(with_gate, feature(impl_restriction))]
85+
| ^^^^^^^^^^^^^^^^
86+
|
87+
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
88+
= note: `#[warn(incomplete_features)]` on by default
89+
90+
error: aborting due to 5 previous errors; 1 warning emitted
91+
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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 BazUnsafeSuper {}
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 BazUnsafeSuper {}
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 BazAutoSelf {}
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 BazAutoSelf {}
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[E0658]: `impl` restrictions are experimental
82+
--> $DIR/recover-incorrect-impl-restriction.rs:8:9
83+
|
84+
LL | pub impl(crate::foo) trait Baz {}
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/recover-incorrect-impl-restriction.rs:10:16
93+
|
94+
LL | pub unsafe impl(crate::foo) trait BazUnsafeSuper {}
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/recover-incorrect-impl-restriction.rs:12:14
103+
|
104+
LL | pub auto impl(crate::foo) trait BazAutoSelf {}
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/recover-incorrect-impl-restriction.rs:14:15
113+
|
114+
LL | pub const impl(crate::foo) trait BazConst {}
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/recover-incorrect-impl-restriction.rs:16:22
123+
|
124+
LL | pub const unsafe impl(crate::foo) trait BazConstUnsafe {}
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: aborting due to 10 previous errors
132+
133+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)