reword the message to suggest surrounding with parentheses

This commit is contained in:
yukang 2023-06-06 23:56:46 +08:00
parent 3983881d4e
commit e3071eaa60
4 changed files with 10 additions and 7 deletions

View File

@ -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

View File

@ -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)))
})
}

View File

@ -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 }) {
| + +

View File

@ -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() {
| + +