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-06-11 00:35:36 +0000
committerbors <bors@rust-lang.org>2023-06-11 00:35:36 +0000
commit970058e16b307e1cff01e2ddb084d2e8d14ea8be (patch)
tree8d33cb2cd310d8dcd2bc2ddf27891c2f0c848601 /compiler/rustc_parse/src/parser
parentb8a50010de397df570b38fe67bda435b665e2d86 (diff)
parent46b64aaef097cab420311834eb58b5d05ea408a7 (diff)
downloadrust-970058e16b307e1cff01e2ddb084d2e8d14ea8be.tar.gz
rust-970058e16b307e1cff01e2ddb084d2e8d14ea8be.zip
Auto merge of #112512 - matthiaskrgr:rollup-o2jh1jx, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #112475 (Fix issue for module name when surround the struct literal with parentheses)
 - #112477 (Give more helpful progress messages in `Assemble`)
 - #112484 (Fix ntdll linkage issues on Windows UWP platforms)
 - #112492 (Migrate GUI colors test to original CSS color format)
 - #112493 (iat selection: normalize self ty & completely erase bound vars)
 - #112497 (abs_sub: fix typo 0[-:][+.]0)
 - #112498 (Update links to Rust Reference in diagnostic)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index c1454039685..228eff1269f 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -751,13 +751,24 @@ impl<'a> Parser<'a> {
                     tail.could_be_bare_literal = true;
                     if maybe_struct_name.is_ident() && can_be_struct_literal {
                         // Account for `if Example { a: one(), }.is_pos() {}`.
-                        Err(self.sess.create_err(StructLiteralNeedingParens {
-                            span: maybe_struct_name.span.to(expr.span),
-                            sugg: StructLiteralNeedingParensSugg {
-                                before: maybe_struct_name.span.shrink_to_lo(),
-                                after: expr.span.shrink_to_hi(),
-                            },
-                        }))
+                        // expand `before` so that we take care of module path such as:
+                        // `foo::Bar { ... } `
+                        // we expect to suggest `(foo::Bar { ... })` instead of `foo::(Bar { ... })`
+                        let sm = self.sess.source_map();
+                        let before = maybe_struct_name.span.shrink_to_lo();
+                        if let Ok(extend_before) = sm.span_extend_prev_while(before, |t| {
+                            t.is_alphanumeric() || t == ':' || t == '_'
+                        }) {
+                            Err(self.sess.create_err(StructLiteralNeedingParens {
+                                span: maybe_struct_name.span.to(expr.span),
+                                sugg: StructLiteralNeedingParensSugg {
+                                    before: extend_before.shrink_to_lo(),
+                                    after: expr.span.shrink_to_hi(),
+                                },
+                            }))
+                        } else {
+                            return None;
+                        }
                     } else {
                         self.sess.emit_err(StructLiteralBodyWithoutPath {
                             span: expr.span,