about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-03-28 18:42:59 +0000
committerbors <bors@rust-lang.org>2022-03-28 18:42:59 +0000
commitee915c34e2f33a07856a9e39be7e35e648bfbd5d (patch)
tree9932eb4cd774d38276337184a18432f49db158c8 /compiler/rustc_parse/src/parser
parent600ec284838c52d1f6657c2cf0097b58970b133b (diff)
parent1f33cd1827b7e2d0f7e5ea0d4469f83f1cf19130 (diff)
downloadrust-ee915c34e2f33a07856a9e39be7e35e648bfbd5d.tar.gz
rust-ee915c34e2f33a07856a9e39be7e35e648bfbd5d.zip
Auto merge of #95414 - Dylan-DPC:rollup-9hbshd0, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #93787 (parallel_compiler: hide dependencies behind feature)
 - #95318 (diagnostics: correct generic bounds with doubled colon)
 - #95328 (Fix yet another Box<T, A> ICE)
 - #95397 (Link to std::io's platform-specific behavior disclaimer)
 - #95407 (Inline u8::is_utf8_char_boundary)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs28
-rw-r--r--compiler/rustc_parse/src/parser/generics.rs1
2 files changed, 29 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index b5b628a3f55..534fd0d4816 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -2369,6 +2369,34 @@ impl<'a> Parser<'a> {
         Err(err)
     }
 
+    crate fn maybe_recover_bounds_doubled_colon(&mut self, ty: &Ty) -> PResult<'a, ()> {
+        let TyKind::Path(qself, path) = &ty.kind else { return Ok(()) };
+        let qself_position = qself.as_ref().map(|qself| qself.position);
+        for (i, segments) in path.segments.windows(2).enumerate() {
+            if qself_position.map(|pos| i < pos).unwrap_or(false) {
+                continue;
+            }
+            if let [a, b] = segments {
+                let (a_span, b_span) = (a.span(), b.span());
+                let between_span = a_span.shrink_to_hi().to(b_span.shrink_to_lo());
+                if self.span_to_snippet(between_span).as_ref().map(|a| &a[..]) == Ok(":: ") {
+                    let mut err = self.struct_span_err(
+                        path.span.shrink_to_hi(),
+                        "expected `:` followed by trait or lifetime",
+                    );
+                    err.span_suggestion(
+                        between_span,
+                        "use single colon",
+                        ": ".to_owned(),
+                        Applicability::MachineApplicable,
+                    );
+                    return Err(err);
+                }
+            }
+        }
+        Ok(())
+    }
+
     /// Parse and throw away a parenthesized comma separated
     /// sequence of patterns until `)` is reached.
     fn skip_pat_list(&mut self) -> PResult<'a, ()> {
diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs
index d625080dee4..29fe2b76101 100644
--- a/compiler/rustc_parse/src/parser/generics.rs
+++ b/compiler/rustc_parse/src/parser/generics.rs
@@ -312,6 +312,7 @@ impl<'a> Parser<'a> {
                 id: ast::DUMMY_NODE_ID,
             }))
         } else {
+            self.maybe_recover_bounds_doubled_colon(&ty)?;
             self.unexpected()
         }
     }