about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-04-09 09:30:51 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2025-04-09 15:00:30 +1000
commitf419b18d16be992b5db21e0008aa7be16f92803f (patch)
tree116f660c719fad625d4d206813e46fea297c6769 /compiler/rustc_parse/src
parentd4f880f8ce832cd7560bb2f1ebc34f967055ffd7 (diff)
downloadrust-f419b18d16be992b5db21e0008aa7be16f92803f.tar.gz
rust-f419b18d16be992b5db21e0008aa7be16f92803f.zip
Return early on an error path in `parse_item_impl`.
Currently the code continues, using an empty path, but it doesn't need
to.
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 3647bf2c378..915a30e5469 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -602,21 +602,13 @@ impl<'a> Parser<'a> {
         let polarity = self.parse_polarity();
 
         // Parse both types and traits as a type, then reinterpret if necessary.
-        let err_path = |span| ast::Path::from_ident(Ident::new(kw::Empty, span));
         let ty_first = if self.token.is_keyword(kw::For) && self.look_ahead(1, |t| t != &token::Lt)
         {
             let span = self.prev_token.span.between(self.token.span);
-            self.dcx().emit_err(errors::MissingTraitInTraitImpl {
+            return Err(self.dcx().create_err(errors::MissingTraitInTraitImpl {
                 span,
                 for_span: span.to(self.token.span),
-            });
-
-            P(Ty {
-                kind: TyKind::Path(None, err_path(span)),
-                span,
-                id: DUMMY_NODE_ID,
-                tokens: None,
-            })
+            }));
         } else {
             self.parse_ty_with_generics_recovery(&generics)?
         };
@@ -671,7 +663,7 @@ impl<'a> Parser<'a> {
                                 span: ty_first.span,
                             });
                         }
-                        err_path(ty_first.span)
+                        ast::Path::from_ident(Ident::new(kw::Empty, ty_first.span))
                     }
                 };
                 let trait_ref = TraitRef { path, ref_id: ty_first.id };