forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#54181 - vi:hint_and_or, r=estebank
Suggest && and || instead of 'and' and 'or' Resolves rust-lang#54109. Note: competing pull reqeust: rust-lang#54179 r? @csmoe
- Loading branch information
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn test_and() { | ||
let a = true; | ||
let b = false; | ||
if a and b { | ||
//~^ ERROR expected `{`, found `and` | ||
println!("both"); | ||
} | ||
} | ||
|
||
fn test_or() { | ||
let a = true; | ||
let b = false; | ||
if a or b { | ||
//~^ ERROR expected `{`, found `or` | ||
println!("both"); | ||
} | ||
} | ||
|
||
fn test_and_par() { | ||
let a = true; | ||
let b = false; | ||
if (a and b) { | ||
//~^ ERROR expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `and` | ||
println!("both"); | ||
} | ||
} | ||
|
||
fn test_or_par() { | ||
let a = true; | ||
let b = false; | ||
if (a or b) { | ||
//~^ ERROR expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `or` | ||
println!("both"); | ||
} | ||
} | ||
|
||
fn test_while_and() { | ||
let a = true; | ||
let b = false; | ||
while a and b { | ||
//~^ ERROR expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `and` | ||
println!("both"); | ||
} | ||
} | ||
|
||
fn test_while_or() { | ||
let a = true; | ||
let b = false; | ||
while a or b { | ||
//~^ ERROR expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `or` | ||
println!("both"); | ||
} | ||
} | ||
|
||
fn main() { | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
error: expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `and` | ||
--> $DIR/issue-54109-and_instead_of_ampersands.rs:50:13 | ||
| | ||
LL | while a and b { | ||
| ^^^ | ||
| | | ||
| expected one of `!`, `.`, `::`, `?`, `{`, or an operator 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:59:13 | ||
| | ||
LL | while a or b { | ||
| ^^ | ||
| | | ||
| expected one of `!`, `.`, `::`, `?`, `{`, or an operator here | ||
| help: use `||` instead of `or` for the boolean operator | ||
|
||
error: aborting due to 6 previous errors | ||
|