-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Try this snippet: playground
pub fn strip_prefix<'a, T>(s: &'a [T], prefix: &[T]) -> Option<&'a [T]>
// where
// T: PartialEq
{
let n = prefix.len();
if n <= s.len() {
let (head, tail) = s.split_at(n);
if head == prefix {
return Some(tail);
}
}
None
}
The compiler errors out:
error[E0369]: binary operation `==` cannot be applied to type `&[T]`
--> src/lib.rs:8:17
|
8 | if head == prefix {
| ---- ^^ ------ &[T]
| |
| &[T]
error: aborting due to previous error
For more information about this error, try `rustc --explain E0369`.
It would be nice if the compiler could suggest adding PartialEq
bound for T
.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.