-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest type param trait bound for binop only when appropriate
Verify that the binop trait *is* implemented for the types *if* all the involved type parameters are replaced with fresh inferred types. When this is the case, it means that the type parameter was indeed missing a trait bound. If this is not the case, provide a generic `note` refering to the type that doesn't implement the expected trait.
- Loading branch information
Showing
8 changed files
with
78 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub fn foo<T>(s: S<T>, t: S<T>) { | ||
let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `S<T>` | ||
} | ||
|
||
struct S<T>(T); | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0369]: binary operation `==` cannot be applied to type `S<T>` | ||
--> $DIR/invalid-bin-op.rs:2:15 | ||
| | ||
LL | let _ = s == t; | ||
| - ^^ - S<T> | ||
| | | ||
| S<T> | ||
| | ||
= note: the trait `std::cmp::PartialEq` is not implemented for `S<T>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0369`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
// run-rustfix | ||
|
||
pub fn strip_prefix<'a, T: std::cmp::PartialEq>(s: &'a [T], prefix: &[T]) -> Option<&'a [T]> { | ||
let n = prefix.len(); | ||
if n <= s.len() { | ||
let (head, tail) = s.split_at(n); | ||
if head == prefix { //~ ERROR binary operation `==` cannot be applied to type `&[T]` | ||
return Some(tail); | ||
} | ||
} | ||
None | ||
pub fn foo<T: std::cmp::PartialEq>(s: &[T], t: &[T]) { | ||
let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `&[T]` | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
// run-rustfix | ||
|
||
pub fn strip_prefix<'a, T>(s: &'a [T], prefix: &[T]) -> Option<&'a [T]> { | ||
let n = prefix.len(); | ||
if n <= s.len() { | ||
let (head, tail) = s.split_at(n); | ||
if head == prefix { //~ ERROR binary operation `==` cannot be applied to type `&[T]` | ||
return Some(tail); | ||
} | ||
} | ||
None | ||
pub fn foo<T>(s: &[T], t: &[T]) { | ||
let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `&[T]` | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters