about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-14 08:06:40 +0000
committerbors <bors@rust-lang.org>2023-05-14 08:06:40 +0000
commit0a0e045e50352d5b8c5c99e965c16aa978a0cbe1 (patch)
treec2cb8ed5aac700c698ba1af046b721a157cd00d3 /compiler/rustc_parse/src/parser
parentbc888958c9e1fdde09791f15d3421bdc3b6d7d29 (diff)
parentd1cd1273f515eb668578dd58585a75b4e1c3012c (diff)
downloadrust-0a0e045e50352d5b8c5c99e965c16aa978a0cbe1.tar.gz
rust-0a0e045e50352d5b8c5c99e965c16aa978a0cbe1.zip
Auto merge of #111552 - matthiaskrgr:rollup-4nidoti, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #111463 (Better diagnostics for `env!` where variable contains escape)
 - #111477 (better diagnostics for `impl<..> impl Trait for Type`)
 - #111534 (rustdoc-json: Add tests for `#![feature(inherent_associated_types)]`)
 - #111549 ([rustdoc] Convert more GUI tests colors to their original format)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs22
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)
                     }
                 };