Skip to content

Commit 3b8df33

Browse files
committed
reword the message to suggest surrounding with parentheses
1 parent c2227d8 commit 3b8df33

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

compiler/rustc_parse/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ parse_struct_literal_body_without_path =
695695
696696
parse_struct_literal_needing_parens =
697697
invalid struct literal
698-
.suggestion = you might need to surround the struct literal in parentheses
698+
.suggestion = you might need to surround the struct literal with parentheses
699699
700700
parse_struct_literal_not_allowed_here = struct literals are not allowed here
701701
.suggestion = surround the struct literal with parentheses

compiler/rustc_span/src/source_map.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,10 @@ impl SourceMap {
751751
f: impl Fn(char) -> bool,
752752
) -> Result<Span, SpanSnippetError> {
753753
self.span_to_source(span, |s, start, _end| {
754-
let n = s[..start].char_indices().rfind(|&(_, c)| !f(c)).map_or(start, |(i, _)| start - i - 1);
754+
let n = s[..start]
755+
.char_indices()
756+
.rfind(|&(_, c)| !f(c))
757+
.map_or(start, |(i, _)| start - i - 1);
755758
Ok(span.with_lo(span.lo() - BytePos(n as u32)))
756759
})
757760
}

tests/ui/parser/issues/issue-111692.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: invalid struct literal
44
LL | if x == module::Type { x: module::C, y: 1 } {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
help: you might need to surround the struct literal in parentheses
7+
help: you might need to surround the struct literal with parentheses
88
|
99
LL | if x == (module::Type { x: module::C, y: 1 }) {
1010
| + +
@@ -15,7 +15,7 @@ error: invalid struct literal
1515
LL | if x ==module::Type { x: module::C, y: 1 } {
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
|
18-
help: you might need to surround the struct literal in parentheses
18+
help: you might need to surround the struct literal with parentheses
1919
|
2020
LL | if x ==(module::Type { x: module::C, y: 1 }) {
2121
| + +
@@ -26,7 +26,7 @@ error: invalid struct literal
2626
LL | if x == Type { x: module::C, y: 1 } {
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2828
|
29-
help: you might need to surround the struct literal in parentheses
29+
help: you might need to surround the struct literal with parentheses
3030
|
3131
LL | if x == (Type { x: module::C, y: 1 }) {
3232
| + +
@@ -37,7 +37,7 @@ error: invalid struct literal
3737
LL | if x == demo_module::Type { x: module::C, y: 1 } {
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939
|
40-
help: you might need to surround the struct literal in parentheses
40+
help: you might need to surround the struct literal with parentheses
4141
|
4242
LL | if x == (demo_module::Type { x: module::C, y: 1 }) {
4343
| + +

tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: invalid struct literal
44
LL | if Example { a: one(), }.is_pos() {
55
| ^^^^^^^^^^^^^^^^^^^^^
66
|
7-
help: you might need to surround the struct literal in parentheses
7+
help: you might need to surround the struct literal with parentheses
88
|
99
LL | if (Example { a: one(), }).is_pos() {
1010
| + +

0 commit comments

Comments
 (0)