about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2023-06-06 23:56:46 +0800
committeryukang <moorekang@gmail.com>2023-06-10 06:28:35 +0800
commite3071eaa608301bd4106c304e3c2f433d6507500 (patch)
tree6e092f3f1122713954c43d5939ff06a7377742c9
parent3983881d4e00c2b12d1b5b0319b4c61d72926917 (diff)
downloadrust-e3071eaa608301bd4106c304e3c2f433d6507500.tar.gz
rust-e3071eaa608301bd4106c304e3c2f433d6507500.zip
reword the message to suggest surrounding with parentheses
-rw-r--r--compiler/rustc_parse/messages.ftl2
-rw-r--r--compiler/rustc_span/src/source_map.rs5
-rw-r--r--tests/ui/parser/issues/issue-111692.stderr8
-rw-r--r--tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr2
4 files changed, 10 insertions, 7 deletions
diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl
index 9263394508e..35eec2c8e1b 100644
--- a/compiler/rustc_parse/messages.ftl
+++ b/compiler/rustc_parse/messages.ftl
@@ -695,7 +695,7 @@ parse_struct_literal_body_without_path =
 
 parse_struct_literal_needing_parens =
     invalid struct literal
-    .suggestion = you might need to surround the struct literal in parentheses
+    .suggestion = you might need to surround the struct literal with parentheses
 
 parse_struct_literal_not_allowed_here = struct literals are not allowed here
     .suggestion = surround the struct literal with parentheses
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index f354751112f..c53fe084c4d 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -751,7 +751,10 @@ impl SourceMap {
         f: impl Fn(char) -> bool,
     ) -> Result<Span, SpanSnippetError> {
         self.span_to_source(span, |s, start, _end| {
-            let n = s[..start].char_indices().rfind(|&(_, c)| !f(c)).map_or(start, |(i, _)| start - i - 1);
+            let n = s[..start]
+                .char_indices()
+                .rfind(|&(_, c)| !f(c))
+                .map_or(start, |(i, _)| start - i - 1);
             Ok(span.with_lo(span.lo() - BytePos(n as u32)))
         })
     }
diff --git a/tests/ui/parser/issues/issue-111692.stderr b/tests/ui/parser/issues/issue-111692.stderr
index 7b09d47301d..068b0483b0f 100644
--- a/tests/ui/parser/issues/issue-111692.stderr
+++ b/tests/ui/parser/issues/issue-111692.stderr
@@ -4,7 +4,7 @@ error: invalid struct literal
 LL |     if x == module::Type { x: module::C, y: 1 } {
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-help: you might need to surround the struct literal in parentheses
+help: you might need to surround the struct literal with parentheses
    |
 LL |     if x == (module::Type { x: module::C, y: 1 }) {
    |             +                                   +
@@ -15,7 +15,7 @@ error: invalid struct literal
 LL |     if x ==module::Type { x: module::C, y: 1 } {
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-help: you might need to surround the struct literal in parentheses
+help: you might need to surround the struct literal with parentheses
    |
 LL |     if x ==(module::Type { x: module::C, y: 1 }) {
    |            +                                   +
@@ -26,7 +26,7 @@ error: invalid struct literal
 LL |     if x == Type { x: module::C, y: 1 } {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-help: you might need to surround the struct literal in parentheses
+help: you might need to surround the struct literal with parentheses
    |
 LL |     if x == (Type { x: module::C, y: 1 }) {
    |             +                           +
@@ -37,7 +37,7 @@ error: invalid struct literal
 LL |     if x == demo_module::Type { x: module::C, y: 1 } {
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-help: you might need to surround the struct literal in parentheses
+help: you might need to surround the struct literal with parentheses
    |
 LL |     if x == (demo_module::Type { x: module::C, y: 1 }) {
    |             +                                        +
diff --git a/tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr b/tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr
index 7fd7ffc94a5..dedbad90945 100644
--- a/tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr
+++ b/tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr
@@ -4,7 +4,7 @@ error: invalid struct literal
 LL |     if Example { a: one(), }.is_pos() {
    |        ^^^^^^^^^^^^^^^^^^^^^
    |
-help: you might need to surround the struct literal in parentheses
+help: you might need to surround the struct literal with parentheses
    |
 LL |     if (Example { a: one(), }).is_pos() {
    |        +                     +