diff options
| author | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-09-12 22:05:52 +0200 |
|---|---|---|
| committer | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-09-12 22:05:52 +0200 |
| commit | 3f0e69591934bdc90577f2af41c0981ea2d1651b (patch) | |
| tree | 24d4e7bc562dd34653d65b77d36a294b583c6eaa /compiler/rustc_parse/src/parser | |
| parent | c7dbe7a830100c70d59994fd940bf75bb6e39b39 (diff) | |
| download | rust-3f0e69591934bdc90577f2af41c0981ea2d1651b.tar.gz rust-3f0e69591934bdc90577f2af41c0981ea2d1651b.zip | |
Improve error message for missing trait in trait impl
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 10c73fd64bc..04a7948e8c9 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -493,7 +493,20 @@ impl<'a> Parser<'a> { 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.struct_span_err(span, "missing trait in a trait impl").emit(); + self.struct_span_err(span, "missing trait in a trait impl") + .span_suggestion( + span, + "add a trait here", + " Trait ".into(), + Applicability::HasPlaceholders, + ) + .span_suggestion( + span.to(self.token.span), + "for an inherent impl, drop this `for`", + "".into(), + Applicability::MaybeIncorrect, + ) + .emit(); P(Ty { kind: TyKind::Path(None, err_path(span)), span, |
