Skip to content

Commit a06ebec

Browse files
Correctly check never_type feature gating
1 parent 11f32b7 commit a06ebec

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ macro_rules! gate_legacy {
5959
}
6060

6161
pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
62-
PostExpansionVisitor { sess, features }.visit_attribute(attr)
62+
PostExpansionVisitor { sess, features, is_in_generics: false }.visit_attribute(attr)
6363
}
6464

6565
struct PostExpansionVisitor<'a> {
6666
sess: &'a Session,
6767

6868
// `sess` contains a `Features`, but this might not be that one.
6969
features: &'a Features,
70+
is_in_generics: bool,
7071
}
7172

7273
impl<'a> PostExpansionVisitor<'a> {
@@ -349,17 +350,20 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
349350
_ => {}
350351
}
351352
}
353+
let prev = std::mem::replace(&mut self.is_in_generics, true);
352354
visit::walk_generics(self, g);
355+
self.is_in_generics = prev;
353356
}
354357

355358
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) {
356-
if let ast::FnRetTy::Ty(output_ty) = ret_ty {
357-
if let ast::TyKind::Never = output_ty.kind {
358-
// Do nothing.
359-
} else {
360-
self.visit_ty(output_ty)
361-
}
359+
if let ast::FnRetTy::Ty(output_ty) = ret_ty
360+
&& let ast::TyKind::Never = output_ty.kind
361+
&& !self.is_in_generics
362+
{
363+
// Do nothing.
364+
return;
362365
}
366+
visit::walk_fn_ret_ty(self, ret_ty);
363367
}
364368

365369
fn visit_expr(&mut self, e: &'a ast::Expr) {
@@ -489,7 +493,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
489493
pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
490494
maybe_stage_features(sess, features, krate);
491495
check_incompatible_features(sess, features);
492-
let mut visitor = PostExpansionVisitor { sess, features };
496+
let mut visitor = PostExpansionVisitor { sess, features, is_in_generics: false };
493497

494498
let spans = sess.parse_sess.gated_spans.spans.borrow();
495499
macro_rules! gate_all {

0 commit comments

Comments
 (0)