Skip to content

Commit

Permalink
Clean up lookup_op_method
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwang05 committed Nov 30, 2023
1 parent 65606e7 commit 90af6f1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,12 +865,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

fn lookup_op_method(
&self,
lhs: (&'tcx hir::Expr<'tcx>, Ty<'tcx>),
(lhs_expr, lhs_ty): (&'tcx hir::Expr<'tcx>, Ty<'tcx>),
opt_rhs: Option<(&'tcx hir::Expr<'tcx>, Ty<'tcx>)>,
op: Op,
expected: Expectation<'tcx>,
) -> Result<MethodCallee<'tcx>, Vec<FulfillmentError<'tcx>>> {
let (lhs_expr, lhs_ty) = lhs;
let span = match op {
Op::Binary(op, _) => op.span,
Op::Unary(_, span) => span,
Expand Down
46 changes: 23 additions & 23 deletions tests/ui/binop/binary-op-suggest-deref.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/binary-op-suggest-deref.rs:8:12
--> $DIR/binary-op-suggest-deref.rs:6:12
|
LL | if i < 0 {}
| ^ expected `&i64`, found integer
Expand All @@ -10,7 +10,7 @@ LL | if *i < 0 {}
| +

error[E0277]: can't compare `&&{integer}` with `{integer}`
--> $DIR/binary-op-suggest-deref.rs:17:13
--> $DIR/binary-op-suggest-deref.rs:15:13
|
LL | _ = foo == 0;
| ^^ no implementation for `&&{integer} == {integer}`
Expand All @@ -32,7 +32,7 @@ LL | _ = **foo == 0;
| ++

error[E0277]: can't compare `&{integer}` with `{integer}`
--> $DIR/binary-op-suggest-deref.rs:19:13
--> $DIR/binary-op-suggest-deref.rs:17:13
|
LL | _ = foo == &0;
| ^^ no implementation for `&{integer} == {integer}`
Expand All @@ -55,7 +55,7 @@ LL | _ = *foo == &0;
| +

error[E0277]: can't compare `&&&&&&{integer}` with `{integer}`
--> $DIR/binary-op-suggest-deref.rs:21:17
--> $DIR/binary-op-suggest-deref.rs:19:17
|
LL | _ = &&&&foo == 0;
| ^^ no implementation for `&&&&&&{integer} == {integer}`
Expand All @@ -78,7 +78,7 @@ LL + _ = **foo == 0;
|

error[E0277]: can't compare `&{integer}` with `{integer}`
--> $DIR/binary-op-suggest-deref.rs:23:14
--> $DIR/binary-op-suggest-deref.rs:21:14
|
LL | _ = *foo == 0;
| ^^ no implementation for `&{integer} == {integer}`
Expand All @@ -100,7 +100,7 @@ LL | _ = **foo == 0;
| +

error[E0277]: can't compare `&&{integer}` with `{integer}`
--> $DIR/binary-op-suggest-deref.rs:25:15
--> $DIR/binary-op-suggest-deref.rs:23:15
|
LL | _ = &&foo == &&0;
| ^^ no implementation for `&&{integer} == {integer}`
Expand All @@ -126,7 +126,7 @@ LL + _ = foo == &&0;
|

error[E0277]: can't compare `&Box<{integer}>` with `{integer}`
--> $DIR/binary-op-suggest-deref.rs:27:23
--> $DIR/binary-op-suggest-deref.rs:25:23
|
LL | _ = &Box::new(42) == 42;
| ^^ no implementation for `&Box<{integer}> == {integer}`
Expand All @@ -140,7 +140,7 @@ LL + _ = *Box::new(42) == 42;
|

error[E0277]: can't compare `&Box<&Box<&{integer}>>` with `{integer}`
--> $DIR/binary-op-suggest-deref.rs:29:35
--> $DIR/binary-op-suggest-deref.rs:27:35
|
LL | _ = &Box::new(&Box::new(&42)) == 42;
| ^^ no implementation for `&Box<&Box<&{integer}>> == {integer}`
Expand All @@ -154,7 +154,7 @@ LL + _ = ****Box::new(&Box::new(&42)) == 42;
|

error[E0277]: can't compare `{integer}` with `&&{integer}`
--> $DIR/binary-op-suggest-deref.rs:33:11
--> $DIR/binary-op-suggest-deref.rs:31:11
|
LL | _ = 0 == foo;
| ^^ no implementation for `{integer} == &&{integer}`
Expand All @@ -176,7 +176,7 @@ LL | _ = 0 == **foo;
| ++

error[E0277]: can't compare `{integer}` with `&{integer}`
--> $DIR/binary-op-suggest-deref.rs:35:12
--> $DIR/binary-op-suggest-deref.rs:33:12
|
LL | _ = &0 == foo;
| ^^ no implementation for `{integer} == &{integer}`
Expand All @@ -199,7 +199,7 @@ LL | _ = &0 == *foo;
| +

error[E0277]: can't compare `{integer}` with `&&&&&&{integer}`
--> $DIR/binary-op-suggest-deref.rs:37:11
--> $DIR/binary-op-suggest-deref.rs:35:11
|
LL | _ = 0 == &&&&foo;
| ^^ no implementation for `{integer} == &&&&&&{integer}`
Expand All @@ -222,7 +222,7 @@ LL + _ = 0 == **foo;
|

error[E0277]: can't compare `{integer}` with `&{integer}`
--> $DIR/binary-op-suggest-deref.rs:39:11
--> $DIR/binary-op-suggest-deref.rs:37:11
|
LL | _ = 0 == *foo;
| ^^ no implementation for `{integer} == &{integer}`
Expand All @@ -244,7 +244,7 @@ LL | _ = 0 == **foo;
| +

error[E0277]: can't compare `{integer}` with `&&{integer}`
--> $DIR/binary-op-suggest-deref.rs:41:13
--> $DIR/binary-op-suggest-deref.rs:39:13
|
LL | _ = &&0 == &&foo;
| ^^ no implementation for `{integer} == &&{integer}`
Expand All @@ -270,7 +270,7 @@ LL + _ = &&0 == foo;
|

error[E0277]: can't compare `Box<Box<{integer}>>` with `&&{integer}`
--> $DIR/binary-op-suggest-deref.rs:45:33
--> $DIR/binary-op-suggest-deref.rs:43:33
|
LL | _ = &Box::new(Box::new(42)) == &foo;
| ^^ no implementation for `Box<Box<{integer}>> == &&{integer}`
Expand All @@ -286,7 +286,7 @@ LL + _ = **Box::new(Box::new(42)) == **foo;
|

error[E0277]: can't compare `Box<{integer}>` with `&&{integer}`
--> $DIR/binary-op-suggest-deref.rs:47:23
--> $DIR/binary-op-suggest-deref.rs:45:23
|
LL | _ = &Box::new(42) == &foo;
| ^^ no implementation for `Box<{integer}> == &&{integer}`
Expand All @@ -302,7 +302,7 @@ LL + _ = *Box::new(42) == **foo;
|

error[E0277]: can't compare `Box<Box<Box<Box<{integer}>>>>` with `&&{integer}`
--> $DIR/binary-op-suggest-deref.rs:49:53
--> $DIR/binary-op-suggest-deref.rs:47:53
|
LL | _ = &Box::new(Box::new(Box::new(Box::new(42)))) == &foo;
| ^^ no implementation for `Box<Box<Box<Box<{integer}>>>> == &&{integer}`
Expand All @@ -318,7 +318,7 @@ LL + _ = ****Box::new(Box::new(Box::new(Box::new(42)))) == **foo;
|

error[E0277]: can't compare `&&{integer}` with `Box<Box<Box<Box<{integer}>>>>`
--> $DIR/binary-op-suggest-deref.rs:51:14
--> $DIR/binary-op-suggest-deref.rs:49:14
|
LL | _ = &foo == &Box::new(Box::new(Box::new(Box::new(42))));
| ^^ no implementation for `&&{integer} == Box<Box<Box<Box<{integer}>>>>`
Expand All @@ -342,7 +342,7 @@ LL + _ = **foo == ****Box::new(Box::new(Box::new(Box::new(42))));
|

error[E0308]: mismatched types
--> $DIR/binary-op-suggest-deref.rs:55:25
--> $DIR/binary-op-suggest-deref.rs:53:25
|
LL | _ = Box::new(42) == 42;
| ------------ ^^ expected `Box<{integer}>`, found integer
Expand All @@ -358,7 +358,7 @@ LL | _ = Box::new(42) == Box::new(42);
| +++++++++ +

error[E0277]: can't compare `&&{integer}` with `Foo`
--> $DIR/binary-op-suggest-deref.rs:60:13
--> $DIR/binary-op-suggest-deref.rs:58:13
|
LL | _ = &&0 == Foo;
| ^^ no implementation for `&&{integer} == Foo`
Expand All @@ -376,15 +376,15 @@ LL | _ = &&0 == Foo;
and 6 others

error[E0369]: binary operation `==` cannot be applied to type `Foo`
--> $DIR/binary-op-suggest-deref.rs:62:13
--> $DIR/binary-op-suggest-deref.rs:60:13
|
LL | _ = Foo == &&0;
| --- ^^ --- &&{integer}
| |
| Foo
|
note: an implementation of `PartialEq<&&{integer}>` might be missing for `Foo`
--> $DIR/binary-op-suggest-deref.rs:59:5
--> $DIR/binary-op-suggest-deref.rs:57:5
|
LL | struct Foo;
| ^^^^^^^^^^ must implement `PartialEq<&&{integer}>`
Expand All @@ -395,7 +395,7 @@ LL | struct Foo;
|

error[E0277]: can't compare `&String` with `str`
--> $DIR/binary-op-suggest-deref.rs:71:20
--> $DIR/binary-op-suggest-deref.rs:69:20
|
LL | _ = string_ref == partial[..3];
| ^^ no implementation for `&String == str`
Expand All @@ -412,7 +412,7 @@ LL | _ = *string_ref == partial[..3];
| +

error[E0277]: can't compare `str` with `&String`
--> $DIR/binary-op-suggest-deref.rs:73:22
--> $DIR/binary-op-suggest-deref.rs:71:22
|
LL | _ = partial[..3] == string_ref;
| ^^ no implementation for `str == &String`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/dst/issue-113447.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: can't compare `&[u8; 1]` with `[{integer}; 1]`
--> $DIR/issue-113447.rs:24:20
--> $DIR/issue-113447.rs:22:20
|
LL | let _ = &[0u8] == [0xAA];
| ^^ no implementation for `&[u8; 1] == [{integer}; 1]`
Expand Down

0 comments on commit 90af6f1

Please sign in to comment.