Skip to content

Commit 0345b89

Browse files
add ui tests
1 parent b44e5dc commit 0345b89

4 files changed

Lines changed: 228 additions & 0 deletions

File tree

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 QuxConstAuto {} //[without_gate]~ ERROR impl restrictions are experimental
22+
}
23+
24+
// auto traits cannot be const, so we do not include these combinations in the test.
25+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 QuxConstAuto {}
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: aborting due to 9 previous errors
92+
93+
For more information about this error, try `rustc --explain E0658`.

tests/ui/macros/stringify.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,111 @@ macro_rules! p {
800800
};
801801
}
802802

803+
#[test]
804+
fn test_impl_restriction() {
805+
assert_eq!(
806+
stringify!(pub impl(crate) trait Foo {}),
807+
"pub impl(crate) trait Foo {}"
808+
);
809+
assert_eq!(
810+
stringify!(pub impl(in crate) trait Foo {}),
811+
"pub impl(in crate) trait Foo {}"
812+
);
813+
assert_eq!(
814+
stringify!(pub impl(super) trait Foo {}),
815+
"pub impl(super) trait Foo {}"
816+
);
817+
assert_eq!(
818+
stringify!(pub impl(in super) trait Foo {}),
819+
"pub impl(in super) trait Foo {}"
820+
);
821+
assert_eq!(
822+
stringify!(pub impl(self) trait Foo {}),
823+
"pub impl(self) trait Foo {}"
824+
);
825+
assert_eq!(
826+
stringify!(pub impl(in self) trait Foo {}),
827+
"pub impl(in self) trait Foo {}"
828+
);
829+
assert_eq!(
830+
stringify!(pub impl(in path::to) trait Foo {}),
831+
"pub impl(in path::to) trait Foo {}"
832+
);
833+
assert_eq!(
834+
stringify!(pub impl(in ::path::to) trait Foo {}),
835+
"pub impl(in ::path::to) trait Foo {}"
836+
);
837+
assert_eq!(
838+
stringify!(pub impl(in self::path::to) trait Foo {}),
839+
"pub impl(in self::path::to) trait Foo {}"
840+
);
841+
assert_eq!(
842+
stringify!(pub impl(in super::path::to) trait Foo {}),
843+
"pub impl(in super::path::to) trait Foo {}"
844+
);
845+
assert_eq!(
846+
stringify!(pub impl(in crate::path::to) trait Foo {}),
847+
"pub impl(in crate::path::to) trait Foo {}"
848+
);
849+
850+
assert_eq!(
851+
stringify!(pub auto impl(crate) trait Foo {}),
852+
"pub auto impl(crate) trait Foo {}"
853+
);
854+
assert_eq!(
855+
stringify!(pub auto impl(in crate::path::to) trait Foo {}),
856+
"pub auto impl(in crate::path::to) trait Foo {}"
857+
);
858+
assert_eq!(
859+
stringify!(pub unsafe impl(crate) trait Foo {}),
860+
"pub unsafe impl(crate) trait Foo {}"
861+
);
862+
assert_eq!(
863+
stringify!(pub unsafe impl(in crate::path::to) trait Foo {}),
864+
"pub unsafe impl(in crate::path::to) trait Foo {}"
865+
);
866+
assert_eq!(
867+
stringify!(pub const impl(crate) trait Foo {}),
868+
"pub const impl(crate) trait Foo {}"
869+
);
870+
assert_eq!(
871+
stringify!(pub const impl(in crate::path::to) trait Foo {}),
872+
"pub const impl(in crate::path::to) trait Foo {}"
873+
);
874+
assert_eq!(
875+
stringify!(pub unsafe auto impl(crate) trait Foo {}),
876+
"pub unsafe auto impl(crate) trait Foo {}"
877+
);
878+
assert_eq!(
879+
stringify!(pub unsafe auto impl(in crate::path::to) trait Foo {}),
880+
"pub unsafe auto impl(in crate::path::to) trait Foo {}"
881+
);
882+
assert_eq!(
883+
stringify!(pub const auto impl(crate) trait Foo {}),
884+
"pub const auto impl(crate) trait Foo {}"
885+
);
886+
assert_eq!(
887+
stringify!(pub const auto impl(in crate::path::to) trait Foo {}),
888+
"pub const auto impl(in crate::path::to) trait Foo {}"
889+
);
890+
assert_eq!(
891+
stringify!(pub const unsafe impl(crate) trait Foo {}),
892+
"pub const unsafe impl(crate) trait Foo {}"
893+
);
894+
assert_eq!(
895+
stringify!(pub const unsafe impl(in crate::path::to) trait Foo {}),
896+
"pub const unsafe impl(in crate::path::to) trait Foo {}"
897+
);
898+
assert_eq!(
899+
stringify!(pub const unsafe auto impl(crate) trait Foo {}),
900+
"pub const unsafe auto impl(crate) trait Foo {}"
901+
);
902+
assert_eq!(
903+
stringify!(pub const unsafe auto impl(in crate::path::to) trait Foo {}),
904+
"pub const unsafe auto impl(in crate::path::to) trait Foo {}"
905+
);
906+
}
907+
803908
#[test]
804909
fn test_punct() {
805910
// For all these cases, we should preserve spaces between the tokens.

0 commit comments

Comments
 (0)