Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustc nightly points out a wrong part of line as an error #90101

Closed
maekawatoshiki opened this issue Oct 20, 2021 · 3 comments · Fixed by #90181
Closed

Rustc nightly points out a wrong part of line as an error #90101

maekawatoshiki opened this issue Oct 20, 2021 · 3 comments · Fixed by #90181
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@maekawatoshiki
Copy link
Contributor

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
@maekawatoshiki maekawatoshiki added the C-bug Category: This is a bug. label Oct 20, 2021
@JohnTitor JohnTitor added A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 20, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 20, 2021
@JohnTitor JohnTitor added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Oct 20, 2021
@JohnTitor JohnTitor added this to the 1.57.0 milestone Oct 21, 2021
@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 21, 2021
@hkmatsumoto
Copy link
Member

hkmatsumoto commented Oct 21, 2021

I did a bisection and here is the result.
searched nightlies: from nightly-2021-08-01 to nightly-2021-10-20
regressed nightly: nightly-2021-09-18
searched commit range: e4828d5...9dd4ce8
regressed commit: e366210
regressed PR: #88719
cc @estebank

bisected with cargo-bisect-rustc v0.6.1

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --prompt --test-dir=. --start=2021-08-01 --end=2021-10-20 

@hkmatsumoto
Copy link
Member

I feel the span of the diagnostic before the regression is also erroneous.

error[E0277]: the trait bound `PathBuf: From<Cow<'_, str>>` is not satisfied
 --> src/lib.rs:6:5
  |
6 |     func(Path::new("hello").to_path_buf().to_string_lossy(), "world")
  |     ^^^^ 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/lib.rs:3:20
  |
3 | fn func(path: impl Into<PathBuf>, code: impl Into<String>) {}
  |                    ^^^^^^^^^^^^^ required by this bound in `func`

Should ideally be something like below:

error[E0277]: the trait bound `PathBuf: From<Cow<'_, str>>` is not satisfied
 --> src/lib.rs:6:5
  |
6 |     func(Path::new("hello").to_path_buf().to_string_lossy(), "world")
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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/lib.rs:3:20
  |
3 | fn func(path: impl Into<PathBuf>, code: impl Into<String>) {}
  |                    ^^^^^^^^^^^^^ required by this bound in `func`

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 26, 2021
…r=estebank

fix(rustc_typeck): report function argument errors on matching type

Fixes rust-lang#90101
@bors bors closed this as completed in 8520105 Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants