Skip to content

Don't emit "is not a logical operator" error outside of associative expressions #75658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<'a> Parser<'a> {
}

fn should_continue_as_assoc_expr(&mut self, lhs: &Expr) -> bool {
match (self.expr_is_complete(lhs), self.check_assoc_op().map(|op| op.node)) {
match (self.expr_is_complete(lhs), AssocOp::from_token(&self.token)) {
// Semi-statement forms are odd:
// See https://github.com/rust-lang/rust/issues/29071
(true, None) => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ fn test_and() {
let b = false;

let _ = a and b; //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator

if a and b { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}

Expand All @@ -20,10 +18,8 @@ fn test_or() {
let b = false;

let _ = a or b; //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator

if a or b { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
Expand All @@ -32,7 +28,6 @@ fn test_and_par() {
let a = true;
let b = false;
if (a and b) { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}
}
Expand All @@ -41,7 +36,6 @@ fn test_or_par() {
let a = true;
let b = false;
if (a or b) { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
Expand All @@ -50,7 +44,6 @@ fn test_while_and() {
let a = true;
let b = false;
while a and b { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}
}
Expand All @@ -59,7 +52,6 @@ fn test_while_or() {
let a = true;
let b = false;
while a or b { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,133 +7,69 @@ LL | let _ = a and b;
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:7:15
|
LL | let _ = a and b;
| ^^^ help: use `&&` to perform logical conjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:10:10
|
LL | if a and b {
| ^^^ help: use `&&` to perform logical conjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:10:10
--> $DIR/issue-54109-and_instead_of_ampersands.rs:9:10
|
LL | if a and b {
| ^^^ help: use `&&` to perform logical conjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:22:15
--> $DIR/issue-54109-and_instead_of_ampersands.rs:20:15
|
LL | let _ = a or b;
| ^^ help: use `||` to perform logical disjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:22:15
|
LL | let _ = a or b;
| ^^ help: use `||` to perform logical disjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:25:10
|
LL | if a or b {
| ^^ help: use `||` to perform logical disjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:25:10
--> $DIR/issue-54109-and_instead_of_ampersands.rs:22:10
|
LL | if a or b {
| ^^ help: use `||` to perform logical disjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:34:11
--> $DIR/issue-54109-and_instead_of_ampersands.rs:30:11
|
LL | if (a and b) {
| ^^^ help: use `&&` to perform logical conjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:34:11
|
LL | if (a and b) {
| ^^^ help: use `&&` to perform logical conjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:43:11
|
LL | if (a or b) {
| ^^ help: use `||` to perform logical disjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:43:11
--> $DIR/issue-54109-and_instead_of_ampersands.rs:38:11
|
LL | if (a or b) {
| ^^ help: use `||` to perform logical disjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:52:13
--> $DIR/issue-54109-and_instead_of_ampersands.rs:46:13
|
LL | while a and b {
| ^^^ help: use `&&` to perform logical conjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:52:13
|
LL | while a and b {
| ^^^ help: use `&&` to perform logical conjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:61:13
|
LL | while a or b {
| ^^ help: use `||` to perform logical disjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:61:13
--> $DIR/issue-54109-and_instead_of_ampersands.rs:54:13
|
LL | while a or b {
| ^^ help: use `||` to perform logical disjunction
|
= note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators

error[E0308]: mismatched types
--> $DIR/issue-54109-and_instead_of_ampersands.rs:15:33
--> $DIR/issue-54109-and_instead_of_ampersands.rs:13:33
|
LL | let _recovery_witness: () = 0;
| -- ^ expected `()`, found integer
| |
| expected due to this

error: aborting due to 17 previous errors
error: aborting due to 9 previous errors

For more information about this error, try `rustc --explain E0308`.
8 changes: 0 additions & 8 deletions src/test/ui/did_you_mean/issue-54109-without-witness.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ fn test_and() {
let b = false;

let _ = a && b; //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator

if a && b { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}
}
Expand All @@ -24,10 +22,8 @@ fn test_or() {
let b = false;

let _ = a || b; //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator

if a || b { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
Expand All @@ -36,7 +32,6 @@ fn test_and_par() {
let a = true;
let b = false;
if (a && b) { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}
}
Expand All @@ -45,7 +40,6 @@ fn test_or_par() {
let a = true;
let b = false;
if (a || b) { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
Expand All @@ -54,7 +48,6 @@ fn test_while_and() {
let a = true;
let b = false;
while a && b { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}
}
Expand All @@ -63,7 +56,6 @@ fn test_while_or() {
let a = true;
let b = false;
while a || b { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
8 changes: 0 additions & 8 deletions src/test/ui/did_you_mean/issue-54109-without-witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ fn test_and() {
let b = false;

let _ = a and b; //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator

if a and b { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}
}
Expand All @@ -24,10 +22,8 @@ fn test_or() {
let b = false;

let _ = a or b; //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator

if a or b { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
Expand All @@ -36,7 +32,6 @@ fn test_and_par() {
let a = true;
let b = false;
if (a and b) { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}
}
Expand All @@ -45,7 +40,6 @@ fn test_or_par() {
let a = true;
let b = false;
if (a or b) { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
Expand All @@ -54,7 +48,6 @@ fn test_while_and() {
let a = true;
let b = false;
while a and b { //~ ERROR `and` is not a logical operator
//~| ERROR `and` is not a logical operator
println!("both");
}
}
Expand All @@ -63,7 +56,6 @@ fn test_while_or() {
let a = true;
let b = false;
while a or b { //~ ERROR `or` is not a logical operator
//~| ERROR `or` is not a logical operator
println!("both");
}
}
Loading