Rollup merge of #120552 - GuillaumeGomez:never-type-feature-gate, r=compiler-errors

Correctly check `never_type` feature gating

Fixes #120542.

The feature wasn't tested on return type of a generic function type, so it got under the radar in https://github.com/rust-lang/rust/pull/120316.

r? ```@compiler-errors```
This commit is contained in:
Matthias Krüger 2024-02-04 19:42:11 +01:00 committed by GitHub
commit c2ad283f4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 1 deletions

View File

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

View File

@ -13,5 +13,14 @@ impl Foo for Meeshka {
type Wub = !; //~ ERROR type is experimental
}
fn look_ma_no_feature_gate<F: FnOnce() -> !>() {} //~ ERROR type is experimental
fn tadam(f: &dyn Fn() -> !) {} //~ ERROR type is experimental
fn panic() -> ! {
panic!();
}
fn toudoum() -> impl Fn() -> ! { //~ ERROR type is experimental
panic
}
fn main() {
}

View File

@ -48,6 +48,36 @@ LL | type Wub = !;
= help: add `#![feature(never_type)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 5 previous errors
error[E0658]: the `!` type is experimental
--> $DIR/feature-gate-never_type.rs:16:43
|
LL | fn look_ma_no_feature_gate<F: FnOnce() -> !>() {}
| ^
|
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
= help: add `#![feature(never_type)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: the `!` type is experimental
--> $DIR/feature-gate-never_type.rs:17:26
|
LL | fn tadam(f: &dyn Fn() -> !) {}
| ^
|
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
= help: add `#![feature(never_type)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: the `!` type is experimental
--> $DIR/feature-gate-never_type.rs:21:30
|
LL | fn toudoum() -> impl Fn() -> ! {
| ^
|
= note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
= help: add `#![feature(never_type)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -0,0 +1,7 @@
// build-pass
trait X<const N: i32> {}
fn hello<T: X<{ fn hello() -> ! { loop {} } 1 }>>() {}
fn main() {}