-
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 lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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
I saw this broken code on IRC:
pub trait JoinWithString {
fn join(self, separator: &'static str) -> String;
}
impl<X> JoinWithString for X
where X: Iterator<Item = String>
{
fn join(self, separator: &'static str) -> String {
unimplemented!()
}
}
fn main() {
let a: Vec<std::path::PathBuf> = Vec::new();
a.iter().map(|x| x.to_str().unwrap()).join(":");
}
I know why it's broken, but I don't like the error message:
error: no method named `join` found for type `std::iter::Map<std::slice::Iter<'_, std::path::PathBuf>, [closure@<anon>:16:18: 16:41]>` in the current scope
--> <anon>:16:43
|>
16 |> a.iter().map(|x| x.to_str().unwrap()).join(":");
|> ^^^^
note: the method `join` exists but the following trait bounds were not satisfied: `&std::iter::Map<std::slice::Iter<'_, std::path::PathBuf>, [closure@<anon>:16:18: 16:41]> : std::iter::Iterator`
help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `join`, perhaps you need to implement it:
help: candidate #1: `JoinWithString`
- The
note
just told me that the problem is the trait bounds, so it is superfluous to suggest importing a trait (even without thenote
, it doesn't need to be imported so thehelp
is useless). - The
note
saysIterator
is not satisfied, which is not helpful. The problem is thatIterator<Item=String>
is not satisfied.
MatthieuBizien, Yevgnen, Zireael07, JoakimThorsen and zoechi
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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.