Skip to content

Commit 6f25d87

Browse files
committed
Update tests
1 parent 8121826 commit 6f25d87

7 files changed

+510
-41
lines changed

tests/ui/binop/binary-op-suggest-deref.fixed

-8
This file was deleted.
+70-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,75 @@
1-
// Issue #52544
2-
// run-rustfix
1+
#![allow(dead_code)]
32

4-
fn main() {
3+
fn foo() {
4+
// Issue #52544
55
let i: &i64 = &1;
66
if i < 0 {}
77
//~^ ERROR mismatched types [E0308]
88
}
9+
10+
fn bar() {
11+
// Issue #40660
12+
let foo = &&0;
13+
14+
// Dereference LHS
15+
_ = foo == 0;
16+
//~^ERROR can't compare `&&{integer}` with `{integer}` [E0277]
17+
_ = foo == &0;
18+
//~^ERROR can't compare `&{integer}` with `{integer}` [E0277]
19+
_ = &&&&foo == 0;
20+
//~^ERROR can't compare `&&&&&&{integer}` with `{integer}` [E0277]
21+
_ = *foo == 0;
22+
//~^ERROR can't compare `&{integer}` with `{integer}` [E0277]
23+
_ = &&foo == &&0;
24+
//~^ERROR can't compare `&&{integer}` with `{integer}` [E0277]
25+
_ = &Box::new(42) == 42;
26+
//~^ERROR can't compare `&Box<{integer}>` with `{integer}` [E0277]
27+
_ = &Box::new(&Box::new(&42)) == 42;
28+
//~^ERROR can't compare `&Box<&Box<&{integer}>>` with `{integer}` [E0277]
29+
30+
// Dereference RHS
31+
_ = 0 == foo;
32+
//~^ERROR can't compare `{integer}` with `&&{integer}` [E0277]
33+
_ = &0 == foo;
34+
//~^ERROR can't compare `{integer}` with `&{integer}` [E0277]
35+
_ = 0 == &&&&foo;
36+
//~^ERROR can't compare `{integer}` with `&&&&&&{integer}` [E0277]
37+
_ = 0 == *foo;
38+
//~^ERROR can't compare `{integer}` with `&{integer}` [E0277]
39+
_ = &&0 == &&foo;
40+
//~^ERROR can't compare `{integer}` with `&&{integer}` [E0277]
41+
42+
// Dereference both sides
43+
_ = &Box::new(Box::new(42)) == &foo;
44+
//~^ERROR can't compare `Box<Box<{integer}>>` with `&&{integer}` [E0277]
45+
_ = &Box::new(42) == &foo;
46+
//~^ERROR can't compare `Box<{integer}>` with `&&{integer}` [E0277]
47+
_ = &Box::new(Box::new(Box::new(Box::new(42)))) == &foo;
48+
//~^ERROR can't compare `Box<Box<Box<Box<{integer}>>>>` with `&&{integer}` [E0277]
49+
_ = &foo == &Box::new(Box::new(Box::new(Box::new(42))));
50+
//~^ERROR can't compare `&&{integer}` with `Box<Box<Box<Box<{integer}>>>>` [E0277]
51+
52+
// Don't suggest dereferencing the LHS; suggest boxing the RHS instead
53+
_ = Box::new(42) == 42;
54+
//~^ERROR mismatched types [E0308]
55+
56+
// Don't suggest dereferencing with types that can't be compared
57+
struct Foo;
58+
_ = &&0 == Foo;
59+
//~^ERROR can't compare `&&{integer}` with `Foo` [E0277]
60+
_ = Foo == &&0;
61+
//~^ERROR binary operation `==` cannot be applied to type `Foo` [E0369]
62+
}
63+
64+
fn baz() {
65+
// Issue #44695
66+
let owned = "foo".to_owned();
67+
let string_ref = &owned;
68+
let partial = "foobar";
69+
_ = string_ref == partial[..3];
70+
//~^ERROR can't compare `&String` with `str` [E0277]
71+
_ = partial[..3] == string_ref;
72+
//~^ERROR can't compare `str` with `&String` [E0277]
73+
}
74+
75+
fn main() {}

0 commit comments

Comments
 (0)