Closed
Description
I tried this code (playground):
use std::path::{Path, PathBuf};
fn func(path: impl Into<PathBuf>, code: impl Into<String>) {}
fn main() {
func(Path::new("hello").to_path_buf().to_string_lossy(), "world")
}
and rustc shows the following error:
error[E0277]: the trait bound `PathBuf: From<Cow<'_, str>>` is not satisfied
--> src/main.rs:6:62
|
6 | func(Path::new("hello").to_path_buf().to_string_lossy(), "world")
| ---- required by a bound introduced by this call ^^^^^^^ the trait `From<Cow<'_, str>>` is not implemented for `PathBuf`
|
= help: the following implementations were found:
<PathBuf as From<&T>>
<PathBuf as From<Box<Path>>>
<PathBuf as From<Cow<'a, Path>>>
<PathBuf as From<OsString>>
<PathBuf as From<String>>
= note: required because of the requirements on the impl of `Into<PathBuf>` for `Cow<'_, str>`
note: required by a bound in `func`
--> src/main.rs:3:20
|
3 | fn func(path: impl Into<PathBuf>, code: impl Into<String>) {}
| ^^^^^^^^^^^^^ required by this bound in `func`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error
Rustc says that "world"
at line 6 is causing the error, but actually it is not.
I think Rustc should point out Path::new("hello").to_path_buf().to_string_lossy()
instead.
Rustc version
# rustc --version --verbose
rustc 1.58.0-nightly (1af55d19c 2021-10-19)
binary: rustc
commit-hash: 1af55d19c7a9189374d89472f97dc119659bb67e
commit-date: 2021-10-19
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0