about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-07 18:53:50 +0000
committerbors <bors@rust-lang.org>2024-08-07 18:53:50 +0000
commitf2deab375c9efd0b92c43fbc092f056f2a9875ce (patch)
tree96d8a0b4d2e3f6d022f1e089ed27269f2416c00f
parent5ead90f13ae3e03f0c346aea3198f18298960d83 (diff)
parent8225f2a79361590b3f6b1e9a819275f18d6e32a1 (diff)
downloadrust-f2deab375c9efd0b92c43fbc092f056f2a9875ce.tar.gz
rust-f2deab375c9efd0b92c43fbc092f056f2a9875ce.zip
Auto merge of #13232 - Alexendoo:path-prefix, r=flip1995
Add path prefixes back when compiling `clippy_dev` and `lintcheck`

`cargo dev` and `cargo lintcheck` use `--manifest-path` to select the package to compile, with this Cargo changes the CWD to the package's containing directory meaning paths in diagnostics start from e.g. `src/` instead of `clippy_dev/src/`

Lintcheck uses a `--remap-path-prefix` trick when linting crates to re-add the directory name in diagnostics:

https://github.com/rust-lang/rust-clippy/blob/5ead90f13ae3e03f0c346aea3198f18298960d83/lintcheck/src/main.rs#L93-L94

https://github.com/rust-lang/rust-clippy/blob/5ead90f13ae3e03f0c346aea3198f18298960d83/lintcheck/src/main.rs#L102-L103

It works well as far as I can tell, when absolute paths appear they stay absolute and do not have the prefix added

[`profile-rustflags`](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#profile-rustflags-option) allows us to set per package `RUSTFLAGS` in order to use the same trick on the `clippy_dev` and `lintcheck` packages themselves

Now when you run into warnings/errors the filename will be correctly clickable

Before
```
error[E0425]: cannot find value `moo` in this scope
  --> src/lib.rs:41:5
   |
41 |     moo;
   |     ^^^ not found in this scope
```

After
```
error[E0425]: cannot find value `moo` in this scope
  --> clippy_dev/src/lib.rs:41:5
   |
41 |     moo;
   |     ^^^ not found in this scope
```

r? `@flip1995`

changelog: none
-rw-r--r--.cargo/config.toml7
1 files changed, 7 insertions, 0 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml
index 7afdd068a99..ce07290d1e1 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -13,6 +13,13 @@ target-dir = "target"
 
 [unstable]
 binary-dep-depinfo = true
+profile-rustflags = true
 
 [profile.dev]
 split-debuginfo = "unpacked"
+
+# Add back the containing directory of the packages we have to refer to using --manifest-path
+[profile.dev.package.clippy_dev]
+rustflags = ["--remap-path-prefix", "=clippy_dev"]
+[profile.dev.package.lintcheck]
+rustflags = ["--remap-path-prefix", "=lintcheck"]