Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f25d87

Browse files
committedNov 29, 2023
Update tests
1 parent 8121826 commit 6f25d87

File tree

7 files changed

+510
-41
lines changed

7 files changed

+510
-41
lines changed
 

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

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 70 additions & 3 deletions
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() {}

‎tests/ui/binop/binary-op-suggest-deref.stderr

Lines changed: 427 additions & 3 deletions
Large diffs are not rendered by default.

‎tests/ui/dst/issue-113447.fixed

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎tests/ui/dst/issue-113447.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// run-rustfix
2-
31
pub struct Bytes;
42

53
impl Bytes {

‎tests/ui/dst/issue-113447.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ LL | let _ = &[0u8] == [0xAA];
1515
<[B] as PartialEq<[A; N]>>
1616
<&[u8] as PartialEq<Bytes>>
1717
and 4 others
18+
help: consider removing the borrow
19+
|
20+
LL - let _ = &[0u8] == [0xAA];
21+
LL + let _ = [0u8] == [0xAA];
22+
|
1823
help: convert the array to a `&[u8]` slice instead
1924
|
2025
LL | let _ = &[0u8] == &[0xAA][..];

‎tests/ui/partialeq_help.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ LL | a == b;
55
| ^^ no implementation for `&T == T`
66
|
77
= help: the trait `PartialEq<T>` is not implemented for `&T`
8+
help: consider dereferencing here
9+
|
10+
LL | *a == b;
11+
| +
812
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
913
|
1014
LL | fn foo<T: PartialEq>(a: &T, b: T) where &T: PartialEq<T> {
@@ -17,6 +21,10 @@ LL | a == b;
1721
| ^^ no implementation for `&T == T`
1822
|
1923
= help: the trait `PartialEq<T>` is not implemented for `&T`
24+
help: consider dereferencing here
25+
|
26+
LL | *a == b;
27+
| +
2028
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
2129
|
2230
LL | fn foo2<T: PartialEq>(a: &T, b: T) where &T: PartialEq<T> {

0 commit comments

Comments
 (0)
Please sign in to comment.