Skip to content

Commit 0cbb9e6

Browse files
committed
expand never type gate test
1 parent e6d2b2a commit 0cbb9e6

File tree

2 files changed

+106
-41
lines changed

2 files changed

+106
-41
lines changed
Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,71 @@
11
// Test that ! errors when used in illegal positions with feature(never_type) disabled
22

3-
trait Foo {
4-
type Wub;
5-
}
3+
mod ungated {
4+
//! Functions returning `!` directly (as in `-> !`) and function pointers doing the same are
5+
//! allowed with no gates.
66
7-
type Ma = (u32, !, i32); //~ ERROR type is experimental
8-
type Meeshka = Vec<!>; //~ ERROR type is experimental
9-
type Mow = &'static fn(!) -> !; //~ ERROR type is experimental
10-
type Skwoz = &'static mut !; //~ ERROR type is experimental
7+
fn panic() -> ! {
8+
panic!();
9+
}
1110

12-
impl Foo for Meeshka {
13-
type Wub = !; //~ ERROR type is experimental
11+
fn takes_fn_ptr(x: fn() -> !) -> ! {
12+
x()
13+
}
1414
}
1515

16-
fn look_ma_no_feature_gate<F: FnOnce() -> !>() {} //~ ERROR type is experimental
17-
fn tadam(f: &dyn Fn() -> !) {} //~ ERROR type is experimental
18-
fn panic() -> ! {
19-
panic!();
20-
}
21-
fn toudoum() -> impl Fn() -> ! { //~ ERROR type is experimental
22-
panic
16+
mod gated {
17+
//! All other mentions of the type are gated.
18+
19+
trait Foo {
20+
type Wub;
21+
}
22+
23+
type Ma = (u32, !, i32); //~ ERROR type is experimental
24+
type Meeshka = Vec<!>; //~ ERROR type is experimental
25+
type Mow = &'static fn(!) -> !; //~ ERROR type is experimental
26+
type Skwoz = &'static mut !; //~ ERROR type is experimental
27+
type Meow = fn() -> Result<(), !>; //~ ERROR type is experimental
28+
29+
impl Foo for Meeshka {
30+
type Wub = !; //~ ERROR type is experimental
31+
}
32+
33+
fn look_ma_no_feature_gate<F: FnOnce() -> !>() {} //~ ERROR type is experimental
34+
35+
fn tadam(f: &dyn Fn() -> !) {} //~ ERROR type is experimental
36+
37+
fn toudoum() -> impl Fn() -> ! { //~ ERROR type is experimental
38+
|| panic!()
39+
}
40+
41+
fn infallible() -> Result<(), !> { //~ ERROR type is experimental
42+
Ok(())
43+
}
2344
}
2445

25-
fn main() {
46+
mod hack {
47+
//! There is a hack which, by exploiting the fact that `fn() -> !` can be named stably and that
48+
//! type system does not interact with stability, allows one to mention the never type while
49+
//! avoiding any and all feature gates. It is generally considered a "hack"/compiler bug, and
50+
//! thus users of this hack resign stability guarantees. However, fixing this is more trouble
51+
//! than good.
52+
53+
trait F {
54+
type Ret;
55+
}
56+
57+
impl<T> F for fn() -> T {
58+
type Ret = T;
59+
}
60+
61+
type Never = <fn() -> ! as F>::Ret;
62+
63+
fn damn(
64+
never: Never,
65+
_: &dyn Fn() -> Never,
66+
) -> (impl Fn() -> Never, &'static mut Never, Never, u8) {
67+
(|| never, never, never, never)
68+
}
2669
}
70+
71+
fn main() {}
Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,103 @@
11
error[E0658]: the `!` type is experimental
2-
--> $DIR/feature-gate-never_type.rs:7:17
2+
--> $DIR/feature-gate-never_type.rs:23:21
33
|
4-
LL | type Ma = (u32, !, i32);
5-
| ^
4+
LL | type Ma = (u32, !, i32);
5+
| ^
66
|
77
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
88
= help: add `#![feature(never_type)]` 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
1010

1111
error[E0658]: the `!` type is experimental
12-
--> $DIR/feature-gate-never_type.rs:8:20
12+
--> $DIR/feature-gate-never_type.rs:24:24
1313
|
14-
LL | type Meeshka = Vec<!>;
15-
| ^
14+
LL | type Meeshka = Vec<!>;
15+
| ^
1616
|
1717
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
1818
= help: add `#![feature(never_type)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the `!` type is experimental
22-
--> $DIR/feature-gate-never_type.rs:9:24
22+
--> $DIR/feature-gate-never_type.rs:25:28
2323
|
24-
LL | type Mow = &'static fn(!) -> !;
25-
| ^
24+
LL | type Mow = &'static fn(!) -> !;
25+
| ^
2626
|
2727
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
2828
= help: add `#![feature(never_type)]` to the crate attributes to enable
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

3131
error[E0658]: the `!` type is experimental
32-
--> $DIR/feature-gate-never_type.rs:10:27
32+
--> $DIR/feature-gate-never_type.rs:26:31
3333
|
34-
LL | type Skwoz = &'static mut !;
35-
| ^
34+
LL | type Skwoz = &'static mut !;
35+
| ^
3636
|
3737
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
3838
= help: add `#![feature(never_type)]` to the crate attributes to enable
3939
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4040

4141
error[E0658]: the `!` type is experimental
42-
--> $DIR/feature-gate-never_type.rs:13:16
42+
--> $DIR/feature-gate-never_type.rs:27:36
4343
|
44-
LL | type Wub = !;
45-
| ^
44+
LL | type Meow = fn() -> Result<(), !>;
45+
| ^
4646
|
4747
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
4848
= help: add `#![feature(never_type)]` to the crate attributes to enable
4949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
5050

5151
error[E0658]: the `!` type is experimental
52-
--> $DIR/feature-gate-never_type.rs:16:43
52+
--> $DIR/feature-gate-never_type.rs:30:20
5353
|
54-
LL | fn look_ma_no_feature_gate<F: FnOnce() -> !>() {}
55-
| ^
54+
LL | type Wub = !;
55+
| ^
5656
|
5757
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
5858
= help: add `#![feature(never_type)]` to the crate attributes to enable
5959
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6060

6161
error[E0658]: the `!` type is experimental
62-
--> $DIR/feature-gate-never_type.rs:17:26
62+
--> $DIR/feature-gate-never_type.rs:33:47
6363
|
64-
LL | fn tadam(f: &dyn Fn() -> !) {}
65-
| ^
64+
LL | fn look_ma_no_feature_gate<F: FnOnce() -> !>() {}
65+
| ^
6666
|
6767
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
6868
= help: add `#![feature(never_type)]` to the crate attributes to enable
6969
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
7070

7171
error[E0658]: the `!` type is experimental
72-
--> $DIR/feature-gate-never_type.rs:21:30
72+
--> $DIR/feature-gate-never_type.rs:35:30
7373
|
74-
LL | fn toudoum() -> impl Fn() -> ! {
74+
LL | fn tadam(f: &dyn Fn() -> !) {}
7575
| ^
7676
|
7777
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
7878
= help: add `#![feature(never_type)]` to the crate attributes to enable
7979
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
8080

81-
error: aborting due to 8 previous errors
81+
error[E0658]: the `!` type is experimental
82+
--> $DIR/feature-gate-never_type.rs:37:34
83+
|
84+
LL | fn toudoum() -> impl Fn() -> ! {
85+
| ^
86+
|
87+
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
88+
= help: add `#![feature(never_type)]` 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]: the `!` type is experimental
92+
--> $DIR/feature-gate-never_type.rs:41:35
93+
|
94+
LL | fn infallible() -> Result<(), !> {
95+
| ^
96+
|
97+
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
98+
= help: add `#![feature(never_type)]` 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: aborting due to 10 previous errors
82102

83103
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)