diff options
| author | y21 <30553356+y21@users.noreply.github.com> | 2023-05-11 21:55:50 +0200 |
|---|---|---|
| committer | y21 <30553356+y21@users.noreply.github.com> | 2023-05-13 10:51:21 +0200 |
| commit | 7fe83345ef0204eedd8ac3847a527466f6853c0b (patch) | |
| tree | 4eebd7ea8dbf0aa0663e32a0b28f65638dee6a1b /compiler/rustc_parse/src/parser | |
| parent | 69fef92ab2f287f072b66fb7b4f62c8bb4acba43 (diff) | |
| download | rust-7fe83345ef0204eedd8ac3847a527466f6853c0b.tar.gz rust-7fe83345ef0204eedd8ac3847a527466f6853c0b.zip | |
improve error for `impl<..> impl Trait for Type`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 840cfe90899..dc18d400f1e 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -603,10 +603,24 @@ impl<'a> Parser<'a> { let path = match ty_first.kind { // This notably includes paths passed through `ty` macro fragments (#46438). TyKind::Path(None, path) => path, - _ => { - self.sess.emit_err(errors::ExpectedTraitInTraitImplFoundType { - span: ty_first.span, - }); + other => { + if let TyKind::ImplTrait(_, bounds) = other + && let [bound] = bounds.as_slice() + { + // Suggest removing extra `impl` keyword: + // `impl<T: Default> impl Default for Wrapper<T>` + // ^^^^^ + let extra_impl_kw = ty_first.span.until(bound.span()); + self.sess + .emit_err(errors::ExtraImplKeywordInTraitImpl { + extra_impl_kw, + impl_trait_span: ty_first.span + }); + } else { + self.sess.emit_err(errors::ExpectedTraitInTraitImplFoundType { + span: ty_first.span, + }); + } err_path(ty_first.span) } }; |
