Correctly check never_type feature gating

This commit is contained in:
Guillaume Gomez 2024-02-01 14:56:41 +01:00
parent 11f32b73e0
commit 2c0030ff2c

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(_) => {