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-11-11 20:11:07 +0000
committerbors <bors@rust-lang.org>2022-11-11 20:11:07 +0000
commit42325c525b9d3885847a3f803abe53c562d289da (patch)
tree1dff3f83bd600c5e0be3762b380d28a3d238d320 /compiler/rustc_parse/src/parser
parent7d85104b96fb2ffe7b638ffbfb1794ef5652bdcf (diff)
parentb74d042be2c237fa1a29e87ed7501410974a0dd9 (diff)
downloadrust-42325c525b9d3885847a3f803abe53c562d289da.tar.gz
rust-42325c525b9d3885847a3f803abe53c562d289da.zip
Auto merge of #104293 - Manishearth:rollup-xj92d0k, r=Manishearth
Rollup of 8 pull requests

Successful merges:

 - #95292 (Allow specialized const trait impls.)
 - #100386 (Make `Sized` coinductive, again)
 - #102215 (Implement the `+whole-archive` modifier for `wasm-ld`)
 - #103468 (Fix unused lint and parser caring about spaces to won't produce invalid code)
 - #103531 (Suggest calling the instance method of the same name when method not found)
 - #103960 (piece of diagnostic migrate)
 - #104051 (update Miri)
 - #104129 (rustdoc: use javascript to layout notable traits popups)

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.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index c609aa93da3..0bbe073fe2a 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -1653,15 +1653,29 @@ impl<'a> Parser<'a> {
             (token::CloseDelim(Delimiter::Parenthesis), Some(begin_par_sp)) => {
                 self.bump();
 
+                let sm = self.sess.source_map();
+                let left = begin_par_sp;
+                let right = self.prev_token.span;
+                let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left) &&
+                        !snip.ends_with(" ") {
+                                " ".to_string()
+                            } else {
+                                "".to_string()
+                            };
+
+                let right_snippet = if let Ok(snip) = sm.span_to_next_source(right) &&
+                        !snip.starts_with(" ") {
+                                " ".to_string()
+                            } else {
+                                "".to_string()
+                        };
+
                 self.sess.emit_err(ParenthesesInForHead {
-                    span: vec![begin_par_sp, self.prev_token.span],
+                    span: vec![left, right],
                     // With e.g. `for (x) in y)` this would replace `(x) in y)`
                     // with `x) in y)` which is syntactically invalid.
                     // However, this is prevented before we get here.
-                    sugg: ParenthesesInForHeadSugg {
-                        left: begin_par_sp,
-                        right: self.prev_token.span,
-                    },
+                    sugg: ParenthesesInForHeadSugg { left, right, left_snippet, right_snippet },
                 });
 
                 // Unwrap `(pat)` into `pat` to avoid the `unused_parens` lint.