-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
510 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,75 @@ | ||
// Issue #52544 | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
|
||
fn main() { | ||
fn foo() { | ||
// Issue #52544 | ||
let i: &i64 = &1; | ||
if i < 0 {} | ||
//~^ ERROR mismatched types [E0308] | ||
} | ||
|
||
fn bar() { | ||
// Issue #40660 | ||
let foo = &&0; | ||
|
||
// Dereference LHS | ||
_ = foo == 0; | ||
//~^ERROR can't compare `&&{integer}` with `{integer}` [E0277] | ||
_ = foo == &0; | ||
//~^ERROR can't compare `&{integer}` with `{integer}` [E0277] | ||
_ = &&&&foo == 0; | ||
//~^ERROR can't compare `&&&&&&{integer}` with `{integer}` [E0277] | ||
_ = *foo == 0; | ||
//~^ERROR can't compare `&{integer}` with `{integer}` [E0277] | ||
_ = &&foo == &&0; | ||
//~^ERROR can't compare `&&{integer}` with `{integer}` [E0277] | ||
_ = &Box::new(42) == 42; | ||
//~^ERROR can't compare `&Box<{integer}>` with `{integer}` [E0277] | ||
_ = &Box::new(&Box::new(&42)) == 42; | ||
//~^ERROR can't compare `&Box<&Box<&{integer}>>` with `{integer}` [E0277] | ||
|
||
// Dereference RHS | ||
_ = 0 == foo; | ||
//~^ERROR can't compare `{integer}` with `&&{integer}` [E0277] | ||
_ = &0 == foo; | ||
//~^ERROR can't compare `{integer}` with `&{integer}` [E0277] | ||
_ = 0 == &&&&foo; | ||
//~^ERROR can't compare `{integer}` with `&&&&&&{integer}` [E0277] | ||
_ = 0 == *foo; | ||
//~^ERROR can't compare `{integer}` with `&{integer}` [E0277] | ||
_ = &&0 == &&foo; | ||
//~^ERROR can't compare `{integer}` with `&&{integer}` [E0277] | ||
|
||
// Dereference both sides | ||
_ = &Box::new(Box::new(42)) == &foo; | ||
//~^ERROR can't compare `Box<Box<{integer}>>` with `&&{integer}` [E0277] | ||
_ = &Box::new(42) == &foo; | ||
//~^ERROR can't compare `Box<{integer}>` with `&&{integer}` [E0277] | ||
_ = &Box::new(Box::new(Box::new(Box::new(42)))) == &foo; | ||
//~^ERROR can't compare `Box<Box<Box<Box<{integer}>>>>` with `&&{integer}` [E0277] | ||
_ = &foo == &Box::new(Box::new(Box::new(Box::new(42)))); | ||
//~^ERROR can't compare `&&{integer}` with `Box<Box<Box<Box<{integer}>>>>` [E0277] | ||
|
||
// Don't suggest dereferencing the LHS; suggest boxing the RHS instead | ||
_ = Box::new(42) == 42; | ||
//~^ERROR mismatched types [E0308] | ||
|
||
// Don't suggest dereferencing with types that can't be compared | ||
struct Foo; | ||
_ = &&0 == Foo; | ||
//~^ERROR can't compare `&&{integer}` with `Foo` [E0277] | ||
_ = Foo == &&0; | ||
//~^ERROR binary operation `==` cannot be applied to type `Foo` [E0369] | ||
} | ||
|
||
fn baz() { | ||
// Issue #44695 | ||
let owned = "foo".to_owned(); | ||
let string_ref = &owned; | ||
let partial = "foobar"; | ||
_ = string_ref == partial[..3]; | ||
//~^ERROR can't compare `&String` with `str` [E0277] | ||
_ = partial[..3] == string_ref; | ||
//~^ERROR can't compare `str` with `&String` [E0277] | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.