Skip to content

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

@ahaoboy

Description

@ahaoboy
Contributor

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]

Activity

added
C-bugCategory: bug
S-triageStatus: This issue is waiting on initial triage.
on Jul 10, 2024
ahaoboy

ahaoboy commented on Jul 10, 2024

@ahaoboy
ContributorAuthor

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

added
A-console-outputArea: Terminal output, colors, progress bar, etc.
A-cargo-targetsArea: selection and definition of targets (lib, bins, examples, tests, benches)
S-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review
S-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.
and removed
S-triageStatus: This issue is waiting on initial triage.
S-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review
on Jul 10, 2024
epage

epage commented on Jul 10, 2024

@epage
Contributor

Couple of questions

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

epage commented on Jul 10, 2024

@epage
Contributor

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

ahaoboy

ahaoboy commented on Jul 10, 2024

@ahaoboy
ContributorAuthor

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"

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

epage commented on Jul 10, 2024

@epage
Contributor

@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

ahaoboy commented on Jul 10, 2024

@ahaoboy
ContributorAuthor

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.

added a commit that references this issue on Nov 6, 2024
d050945
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cargo-targetsArea: selection and definition of targets (lib, bins, examples, tests, benches)A-console-outputArea: Terminal output, colors, progress bar, etc.C-bugCategory: bugO-windowsOS: WindowsS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @epage@ahaoboy

      Issue actions

        The file path in the diagnostic message contains duplicate separators on windows · Issue #14227 · rust-lang/cargo