diff options
| author | bors <bors@rust-lang.org> | 2019-03-18 08:03:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-03-18 08:03:05 +0000 |
| commit | cd45b19bd2d8b4f9a3940a409ea43285019f3280 (patch) | |
| tree | 733bb52b665f169975337964df55691482ddcfe6 /src/libsyntax/parse | |
| parent | 03dafa7da38decbe74fcd8a23d7ec835e637c8e4 (diff) | |
| parent | e19b2289594746ce733588ac444df3fefaad4912 (diff) | |
| download | rust-cd45b19bd2d8b4f9a3940a409ea43285019f3280.tar.gz rust-cd45b19bd2d8b4f9a3940a409ea43285019f3280.zip | |
Auto merge of #58872 - rep-nop:diagnostic-fix-56031, r=petrochenkov
Adds help message in error for invalid `impl for T` syntax Fixes #56031.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index aa70c54a1ef..3e00d948c1a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6732,7 +6732,15 @@ impl<'a> Parser<'a> { }; // Parse both types and traits as a type, then reinterpret if necessary. - let ty_first = self.parse_ty()?; + let err_path = |span| ast::Path::from_ident(Ident::new(keywords::Invalid.name(), span)); + let ty_first = if self.token.is_keyword(keywords::For) && + self.look_ahead(1, |t| t != &token::Lt) { + let span = self.prev_span.between(self.span); + self.struct_span_err(span, "missing trait in a trait impl").emit(); + P(Ty { node: TyKind::Path(None, err_path(span)), span, id: ast::DUMMY_NODE_ID }) + } else { + self.parse_ty()? + }; // If `for` is missing we try to recover. let has_for = self.eat_keyword(keywords::For); @@ -6741,7 +6749,7 @@ impl<'a> Parser<'a> { let ty_second = if self.token == token::DotDot { // We need to report this error after `cfg` expansion for compatibility reasons self.bump(); // `..`, do not add it to expected tokens - Some(P(Ty { node: TyKind::Err, span: self.prev_span, id: ast::DUMMY_NODE_ID })) + Some(DummyResult::raw_ty(self.prev_span, true)) } else if has_for || self.token.can_begin_type() { Some(self.parse_ty()?) } else { @@ -6771,7 +6779,7 @@ impl<'a> Parser<'a> { TyKind::Path(None, path) => path, _ => { self.span_err(ty_first.span, "expected a trait, found type"); - ast::Path::from_ident(Ident::new(keywords::Invalid.name(), ty_first.span)) + err_path(ty_first.span) } }; let trait_ref = TraitRef { path, ref_id: ty_first.id }; |
