about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libsyntax/parse/parser.rs28
-rw-r--r--src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr23
2 files changed, 34 insertions, 17 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a28157106ba..429d1b6bf5e 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -733,10 +733,20 @@ impl<'a> Parser<'a> {
             };
             let mut err = self.fatal(&msg_exp);
             if self.token.is_ident_named("and") {
-                err.help("Use `&&` instead of `and` for the boolean operator");
+                err.span_suggestion_with_applicability(
+                    self.span,
+                    "use `&&` instead of `and` for the boolean operator",
+                    "&&".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
             }
             if self.token.is_ident_named("or") {
-                err.help("Use `||` instead of `or` for the boolean operator");
+                err.span_suggestion_with_applicability(
+                    self.span,
+                    "use `||` instead of `or` for the boolean operator",
+                    "||".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
             }
             let sp = if self.token == token::Token::Eof {
                 // This is EOF, don't want to point at the following char, but rather the last token
@@ -4758,10 +4768,20 @@ impl<'a> Parser<'a> {
             }
 
             if self.token.is_ident_named("and") {
-                e.help("Use `&&` instead of `and` for the boolean operator");
+                e.span_suggestion_with_applicability(
+                    self.span,
+                    "use `&&` instead of `and` for the boolean operator",
+                    "&&".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
             }
             if self.token.is_ident_named("or") {
-                e.help("Use `||` instead of `or` for the boolean operator");
+                e.span_suggestion_with_applicability(
+                    self.span,
+                    "use `||` instead of `or` for the boolean operator",
+                    "||".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
             }
 
             // Check to see if the user has written something like
diff --git a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr
index 9d53cc237e2..74ebb1e757c 100644
--- a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr
+++ b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr
@@ -2,37 +2,34 @@ error: expected `{`, found `and`
   --> $DIR/issue-54109-and_instead_of_ampersands.rs:14:10
    |
 LL |     if a and b {
-   |     --   ^^^
+   |     --   ^^^ help: use `&&` instead of `and` for the boolean operator: `&&`
    |     |
    |     this `if` statement has a condition, but no block
-   |
-   = help: Use `&&` instead of `and` for the boolean operator
 
 error: expected `{`, found `or`
   --> $DIR/issue-54109-and_instead_of_ampersands.rs:23:10
    |
 LL |     if a or b {
-   |     --   ^^
+   |     --   ^^ help: use `||` instead of `or` for the boolean operator: `||`
    |     |
    |     this `if` statement has a condition, but no block
-   |
-   = help: Use `||` instead of `or` for the boolean operator
 
 error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `and`
   --> $DIR/issue-54109-and_instead_of_ampersands.rs:32:11
    |
 LL |     if (a and b) {
-   |           ^^^ expected one of 8 possible tokens here
-   |
-   = help: Use `&&` instead of `and` for the boolean operator
+   |           ^^^
+   |           |
+   |           expected one of 8 possible tokens here
+   |           help: use `&&` instead of `and` for the boolean operator: `&&`
 
 error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `or`
   --> $DIR/issue-54109-and_instead_of_ampersands.rs:41:11
    |
 LL |     if (a or b) {
-   |           ^^ expected one of 8 possible tokens here
-   |
-   = help: Use `||` instead of `or` for the boolean operator
+   |           ^^
+   |           |
+   |           expected one of 8 possible tokens here
+   |           help: use `||` instead of `or` for the boolean operator: `||`
 
 error: aborting due to 4 previous errors
-