-
Notifications
You must be signed in to change notification settings - Fork 13.2k
/
Copy pathbinary-op-suggest-deref.rs
81 lines (71 loc) · 2.69 KB
/
binary-op-suggest-deref.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#![allow(dead_code)]
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];
_ = partial[..3] == string_ref;
}
fn qux() {
// Issue #119352
const FOO: i32 = 42;
let _ = FOO & (*"Sized".to_string().into_boxed_str());
//~^ ERROR the size for values of type `str` cannot be known at compilation time
//~| ERROR no implementation for `i32 & str` [E0277]
}
fn main() {}