-
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-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.P-mediumMedium priorityMedium priorityT-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.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Milestone
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
oli-obk
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.P-mediumMedium priorityMedium priorityT-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.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.