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

The file path in the diagnostic message contains duplicate separators on windows #14227

Closed
ahaoboy opened this issue Jul 10, 2024 · 6 comments · Fixed by #14497
Closed

The file path in the diagnostic message contains duplicate separators on windows #14227

ahaoboy opened this issue Jul 10, 2024 · 6 comments · Fixed by #14497
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug O-windows OS: Windows S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@ahaoboy
Copy link
Contributor

ahaoboy commented Jul 10, 2024

Problem

When using a relative path in a workspace subproject, the file path in the diagnostic message contains duplicate separators

happened

mpv-easy-ext\./src/main.rs:2:7

expected

mpv-easy-ext/src/main.rs:2:7
 cargo clippy
    Checking mpv-easy-ext v0.1.0 (C:\wt\clippy-path\mpv-easy-ext)
warning: unused variable: `a`
 --> mpv-easy-ext\./src/main.rs:2:7
  |
2 |   let a = 1;
  |       ^ help: if this is intentional, prefix it with an underscore: `_a`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `mpv-easy-ext` (bin "mpv") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.18s

Steps

git clone https://github.com/ahaoboy/cargo-clippy-path

cd cargo-clippy-path

cargo clippy

Possible Solution(s)

Use clean-path to transform the output path

Notes

No response

Version

cargo 1.81.0-nightly (154fdac39 2024-07-07)
release: 1.81.0-nightly
commit-hash: 154fdac39ae9629954e19e9986fd2cf2cdd8d964
commit-date: 2024-07-07
host: x86_64-pc-windows-msvc
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:Schannel)
os: Windows 10.0.22635 (Windows 11 Professional) [64-bit]
@ahaoboy ahaoboy added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jul 10, 2024
@ahaoboy
Copy link
Contributor Author

ahaoboy commented Jul 10, 2024

I don't know if it's a problem with cargo itself or if a dependent library doesn't process the path for Windows. rust-lang/rust-clippy#13078

@epage epage added A-console-output Area: Terminal output, colors, progress bar, etc. A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) O-windows OS: Windows S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-triage Status: This issue is waiting on initial triage. S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review labels Jul 10, 2024
@epage
Copy link
Contributor

epage commented Jul 10, 2024

Couple of questions

  • Does this reproduce on stable?
  • Does this reproduce with cargo check?
  • Does cargo metadata show the non-cleaned path?

@epage
Copy link
Contributor

epage commented Jul 10, 2024

Side note: I wonder if this is related to target work I did like #13849.

@ahaoboy
Copy link
Contributor Author

ahaoboy commented Jul 10, 2024

cargo check

    Checking mpv-easy-ext v0.1.0 (C:\wt\clippy-path\mpv-easy-ext)
warning: unused variable: `a`
 --> mpv-easy-ext\./src/main.rs:2:7
  |
2 |   let a = 1;
  |       ^ help: if this is intentional, prefix it with an underscore: `_a`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `mpv-easy-ext` (bin "mpv") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s

 win…\clippy-path   main  

cargo -Vv

cargo 1.79.0 (ffa9cf99a 2024-06-03)
release: 1.79.0
commit-hash: ffa9cf99a594e59032757403d4c780b46dc2c43a
commit-date: 2024-06-03
host: x86_64-pc-windows-msvc
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:Schannel)
os: Windows 10.0.22635 (Windows 11 Professional) [64-bit]

cargo metadata


warning: please specify `--format-version` flag explicitly to avoid compatibility problems
{"packages":[{"name":"mpv-easy-ext","version":"0.1.0","id":"path+file:///C:/wt/clippy-path/mpv-easy-ext#0.1.0","license":"MIT","license_file":null,"description":"mpv-easy rust extension","source":null,"dependencies":[],"targets":[{"kind":["bin"],"crate_types":["bin"],"name":"mpv","src_path":"C:\\wt\\clippy-path\\mpv-easy-ext\\./src/main.rs","edition":"2021","doc":true,"doctest":false,"test":true}],"features":{},"manifest_path":"C:\\wt\\clippy-path\\mpv-easy-ext\\Cargo.toml","metadata":null,"publish":null,"authors":["ahaoboy"],"categories":[],"keywords":[],"readme":"README.md","repository":"https://github.com/mpv-easy/mpv-easy","homepage":null,"documentation":null,"edition":"2021","links":null,"default_run":null,"rust_version":null}],"workspace_members":["path+file:///C:/wt/clippy-path/mpv-easy-ext#0.1.0"],"workspace_default_members":["path+file:///C:/wt/clippy-path/mpv-easy-ext#0.1.0"],"resolve":{"nodes":[{"id":"path+file:///C:/wt/clippy-path/mpv-easy-ext#0.1.0","dependencies":[],"deps":[],"features":[]}],"root":null},"target_directory":"C:\\wt\\clippy-path\\target","version":1,"workspace_root":"C:\\wt\\clippy-path","metadata":null}
  • Does this reproduce on stable?

Yes

  • Does this reproduce with cargo check?

Yes

  • Does cargo metadata show the non-cleaned path?

Yes "src_path":"C:\wt\clippy-path\mpv-easy-ext\./src/main.rs"

@epage epage added S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. labels Jul 10, 2024
@epage
Copy link
Contributor

epage commented Jul 10, 2024

@ahaoboy Can you find a full reproduction case (manfiest, source files, etc). This can be by copy/pasting or a repo. A repo would make sure nothing was accidentally left out.

I'm assuming the problem is in cases like

let path = package_root.join(&bin.path.as_ref().expect("previously resolved").0);

I would assume we would have a call to https://docs.rs/cargo-util/latest/cargo_util/paths/fn.normalize_path.html in there. Might be good to go back some versions to see if this once worked and to identify the root cause to find where the best fix would be.

@ahaoboy
Copy link
Contributor Author

ahaoboy commented Jul 10, 2024

Steps

git clone https://github.com/ahaoboy/cargo-clippy-path

cd cargo-clippy-path

cargo clippy

Ubuntu has same issue

 --> mpv-easy-ext/./src/main.rs:2:7
  |

The solution should not be difficult. Just find where the path mpv-easy-ext/./src/main.rs:2:7 is joined, and then use clean-path to process the following. cargo is too complicated, and I don’t know where the path is concatenated.

PS: Maybe we can use a clean-path-join library? The double separator does not affect the function at present, but it is impossible to jump through the link in some editors and terminals.

linyihai added a commit to linyihai/cargo that referenced this issue Sep 5, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Sep 7, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Sep 7, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Sep 7, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Sep 7, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Sep 9, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Sep 11, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Sep 18, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Oct 11, 2024
linyihai added a commit to linyihai/cargo that referenced this issue Nov 1, 2024
@bors bors closed this as completed in d050945 Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug O-windows OS: Windows S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants