Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwang05 committed Nov 29, 2023
1 parent a68e2e1 commit 4275e80
Show file tree
Hide file tree
Showing 7 changed files with 510 additions and 41 deletions.
8 changes: 0 additions & 8 deletions tests/ui/binop/binary-op-suggest-deref.fixed

This file was deleted.

73 changes: 70 additions & 3 deletions tests/ui/binop/binary-op-suggest-deref.rs
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() {}
Loading

0 comments on commit 4275e80

Please sign in to comment.