Skip to content

Commit f419b18

Browse files
committed
Return early on an error path in parse_item_impl.
Currently the code continues, using an empty path, but it doesn't need to.
1 parent d4f880f commit f419b18

File tree

1 file changed

+3
-11
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+3
-11
lines changed

Diff for: compiler/rustc_parse/src/parser/item.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -602,21 +602,13 @@ impl<'a> Parser<'a> {
602602
let polarity = self.parse_polarity();
603603

604604
// Parse both types and traits as a type, then reinterpret if necessary.
605-
let err_path = |span| ast::Path::from_ident(Ident::new(kw::Empty, span));
606605
let ty_first = if self.token.is_keyword(kw::For) && self.look_ahead(1, |t| t != &token::Lt)
607606
{
608607
let span = self.prev_token.span.between(self.token.span);
609-
self.dcx().emit_err(errors::MissingTraitInTraitImpl {
608+
return Err(self.dcx().create_err(errors::MissingTraitInTraitImpl {
610609
span,
611610
for_span: span.to(self.token.span),
612-
});
613-
614-
P(Ty {
615-
kind: TyKind::Path(None, err_path(span)),
616-
span,
617-
id: DUMMY_NODE_ID,
618-
tokens: None,
619-
})
611+
}));
620612
} else {
621613
self.parse_ty_with_generics_recovery(&generics)?
622614
};
@@ -671,7 +663,7 @@ impl<'a> Parser<'a> {
671663
span: ty_first.span,
672664
});
673665
}
674-
err_path(ty_first.span)
666+
ast::Path::from_ident(Ident::new(kw::Empty, ty_first.span))
675667
}
676668
};
677669
let trait_ref = TraitRef { path, ref_id: ty_first.id };

0 commit comments

Comments
 (0)