Skip to content

Commit 056b18b

Browse files
authored
Unrolled build for rust-lang#120552
Rollup merge of rust-lang#120552 - GuillaumeGomez:never-type-feature-gate, r=compiler-errors Correctly check `never_type` feature gating Fixes rust-lang#120542. The feature wasn't tested on return type of a generic function type, so it got under the radar in rust-lang#120316. r? ```@compiler-errors```
2 parents 268dbbb + 0f21e45 commit 056b18b

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+13
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
362362
}
363363
}
364364

365+
fn visit_generic_args(&mut self, args: &'a ast::GenericArgs) {
366+
// This check needs to happen here because the never type can be returned from a function,
367+
// but cannot be used in any other context. If this check was in `visit_fn_ret_ty`, it
368+
// include both functions and generics like `impl Fn() -> !`.
369+
if let ast::GenericArgs::Parenthesized(generic_args) = args
370+
&& let ast::FnRetTy::Ty(ref ty) = generic_args.output
371+
&& matches!(ty.kind, ast::TyKind::Never)
372+
{
373+
gate!(&self, never_type, ty.span, "the `!` type is experimental");
374+
}
375+
visit::walk_generic_args(self, args);
376+
}
377+
365378
fn visit_expr(&mut self, e: &'a ast::Expr) {
366379
match e.kind {
367380
ast::ExprKind::TryBlock(_) => {

tests/ui/feature-gates/feature-gate-never_type.rs

+9
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,14 @@ impl Foo for Meeshka {
1313
type Wub = !; //~ ERROR type is experimental
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
23+
}
24+
1625
fn main() {
1726
}

tests/ui/feature-gates/feature-gate-never_type.stderr

+31-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,36 @@ LL | type Wub = !;
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

51-
error: aborting due to 5 previous errors
51+
error[E0658]: the `!` type is experimental
52+
--> $DIR/feature-gate-never_type.rs:16:43
53+
|
54+
LL | fn look_ma_no_feature_gate<F: FnOnce() -> !>() {}
55+
| ^
56+
|
57+
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
58+
= help: add `#![feature(never_type)]` 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]: the `!` type is experimental
62+
--> $DIR/feature-gate-never_type.rs:17:26
63+
|
64+
LL | fn tadam(f: &dyn Fn() -> !) {}
65+
| ^
66+
|
67+
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
68+
= help: add `#![feature(never_type)]` 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]: the `!` type is experimental
72+
--> $DIR/feature-gate-never_type.rs:21:30
73+
|
74+
LL | fn toudoum() -> impl Fn() -> ! {
75+
| ^
76+
|
77+
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
78+
= help: add `#![feature(never_type)]` 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: aborting due to 8 previous errors
5282

5383
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// build-pass
2+
3+
trait X<const N: i32> {}
4+
5+
fn hello<T: X<{ fn hello() -> ! { loop {} } 1 }>>() {}
6+
7+
fn main() {}

0 commit comments

Comments
 (0)