mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-03 17:35:28 +03:00
3ad92c9f23
When encountering an unmet predicate, when we point at the trait impls that do exist, if they are all for the same self type, tweak the wording to make it less verbose.
51 lines
1.6 KiB
Rust
51 lines
1.6 KiB
Rust
// compile-fail
|
|
|
|
use std::convert::TryFrom;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
pub struct ToolA(PathBuf);
|
|
//~^ HELP the trait `From<&PathBuf>` is not implemented for `ToolA`
|
|
|
|
impl From<&Path> for ToolA {
|
|
//~^ HELP `ToolA` implements trait `From<T>`
|
|
fn from(p: &Path) -> ToolA {
|
|
ToolA(p.to_path_buf())
|
|
}
|
|
}
|
|
|
|
// Add a different From<T> impl to ensure we suggest the correct cast
|
|
impl From<&str> for ToolA {
|
|
fn from(s: &str) -> ToolA {
|
|
ToolA(PathBuf::from(s))
|
|
}
|
|
}
|
|
|
|
pub struct ToolB(PathBuf);
|
|
//~^ HELP the trait `From<&PathBuf>` is not implemented for `ToolB`
|
|
//~| HELP the trait `From<&PathBuf>` is not implemented for `ToolB`
|
|
|
|
impl TryFrom<&Path> for ToolB {
|
|
//~^ HELP the trait `TryFrom<&PathBuf>` is not implemented for `ToolB`
|
|
//~| HELP the trait `TryFrom<&PathBuf>` is not implemented for `ToolB`
|
|
type Error = ();
|
|
|
|
fn try_from(p: &Path) -> Result<ToolB, ()> {
|
|
Ok(ToolB(p.to_path_buf()))
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let path = PathBuf::new();
|
|
|
|
let _ = ToolA::from(&path);
|
|
//~^ ERROR the trait bound `ToolA: From<&PathBuf>` is not satisfied
|
|
//~| HELP consider casting the `&PathBuf` value to `&Path`
|
|
let _ = ToolB::try_from(&path);
|
|
//~^ ERROR the trait bound `ToolB: TryFrom<&PathBuf>` is not satisfied
|
|
//~| ERROR the trait bound `ToolB: From<&PathBuf>` is not satisfied
|
|
//~| HELP consider casting the `&PathBuf` value to `&Path`
|
|
//~| HELP consider casting the `&PathBuf` value to `&Path`
|
|
//~| HELP for that trait implementation, expected `Path`, found `PathBuf`
|
|
//~| HELP for that trait implementation, expected `Path`, found `PathBuf`
|
|
}
|