Skip to content

Clippy subtree update #124123

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

Merged
merged 81 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
9f5d31e
clear `DefId` when an expression's type changes to non-adt
y21 Mar 29, 2024
24e1071
clippy: fix up `include_str!` spans in diagnostics
notriddle Mar 29, 2024
9d4a368
Reword `arc_with_non_send_sync` note and help messages
Alexendoo Apr 1, 2024
6a6a917
Check for `Default` trait in initial expression
ARandomDev99 Apr 1, 2024
b2ea5ee
fix: incorrect suggestions when `.then` and `.then_some` is used
yuxqiu Jan 4, 2024
9d1f824
fix: check if receiver's hir_id matches expr's hir_id
yuxqiu Jan 5, 2024
5658040
style: fix fmt
yuxqiu Jan 5, 2024
6f6dd88
test: update tests
yuxqiu Jan 13, 2024
e36c7d5
test: add test cases for str
yuxqiu Apr 1, 2024
b89fa53
fix: fix ci errors
yuxqiu Apr 1, 2024
ac18c24
Use `IfLetOrMatch` to avoid repetition of code
ARandomDev99 Apr 2, 2024
ac225a3
Fix #11738: allow `cast` lints in macros
franciscoBSalgueiro Apr 3, 2024
ca92c0a
update messages
danielhuang Apr 3, 2024
38b8056
Fix: #12268: Correct parentheses for needless_borrow suggestion
mira-eanda Apr 4, 2024
a1e76af
Rename ModSep to PathSep
fmease Apr 4, 2024
0ae4a04
Merge commit '9725c4a162502a02c1c67fdca6b797fe09b2b73c' into clippy-s…
flip1995 Apr 4, 2024
a73e751
Auto merge of #12609 - Alexendoo:arc-with-non-send-sync-message, r=Ja…
bors Apr 4, 2024
71e02a0
use `Lrc` instead of the aliased type `Arc` directly
y21 Apr 4, 2024
8253040
Auto merge of #12591 - y21:issue12585, r=Jarcho
bors Apr 4, 2024
08dac85
Auto merge of #12631 - franciscoBSalgueiro:11738, r=blyxyas
bors Apr 4, 2024
d4a8f61
Use check_attributes in doc lints
Alexendoo Apr 5, 2024
42d0970
Add support for ICE reporting in lintcheck
Jacherr Mar 8, 2024
eecff6d
Auto merge of #12439 - Jacherr:issue-12185, r=blyxyas
bors Apr 5, 2024
2a34f23
Prevent PR assignments to `@matthiaskrgr`, `@giraffate`, and `@Centri3`
xFrednet Apr 1, 2024
367f7aa
Auto merge of #12604 - xFrednet:00000-review-vacation, r=matthiaskrgr
bors Apr 6, 2024
6a2cb33
fix incorrect suggestion for `!(a as type >= b)`
folkertdev Apr 3, 2024
1c9e965
Auto merge of #12610 - ARandomDev99:manual_unwrap_or_default-12564, r…
bors Apr 8, 2024
2202493
Auto merge of #12626 - folkertdev:incorrect-boolean-simplification, r…
bors Apr 8, 2024
02b5e1a
Stop exporting `TypeckRootCtxt` and `FnCtxt`.
oli-obk Apr 8, 2024
89b48a2
Thread pattern types through the HIR
oli-obk Jan 31, 2023
c838803
Actually create ranged int types in the type system.
oli-obk Feb 2, 2023
4daaf19
Rollup merge of #122807 - danielhuang:fix-1, r=davidtwco
matthiaskrgr Apr 8, 2024
ce82fa4
Rollup merge of #123625 - oli-obk:private_fnctxt, r=fee1-dead
matthiaskrgr Apr 8, 2024
fa2db5a
Auto merge of #120131 - oli-obk:pattern_types_syntax, r=compiler-errors
bors Apr 8, 2024
db3a927
Fix markdown syntax in str_split_at_newline docs
Wilfred Apr 8, 2024
8ae7eae
fix: Refactor dereference code and fix test
mira-eanda Apr 8, 2024
1b6561f
Auto merge of #12630 - mira-eanda:master, r=Manishearth
bors Apr 8, 2024
3705073
Recognize common prefixes when checking for items with module name su…
modelflat Mar 27, 2024
23225e1
Consistent lint group table in book and README
flip1995 Apr 8, 2024
54e8ad8
Auto merge of #12652 - Wilfred:patch-2, r=Alexendoo
bors Apr 9, 2024
ccc93f9
Auto merge of #12649 - flip1995:book-readme-sync, r=xFrednet
bors Apr 9, 2024
f7d49a3
Turn `duplicated_attributes` into a late lint
GuillaumeGomez Apr 8, 2024
62fd1d5
Auto merge of #12646 - GuillaumeGomez:regression-test-12537, r=blyxyas
bors Apr 9, 2024
d13ccf3
Add a helper for extending a span to include any trailing whitespace
compiler-errors Apr 7, 2024
e5b6d43
fix various comment typos
jqnatividad Apr 10, 2024
8de0a1b
fix varname typo
jqnatividad Apr 10, 2024
d7a8622
Why is this bad explanation typo
jqnatividad Apr 10, 2024
8b5447c
Fix typo in needless_borrows_for_generic_args.rs
cowlicks Apr 10, 2024
fb2e827
Pin remark-lint-maximum-line-length version
Alexendoo Apr 11, 2024
dfd41ad
Auto merge of #12668 - Alexendoo:remark-version, r=flip1995
bors Apr 11, 2024
4632375
Auto merge of #12665 - cowlicks:patch-1, r=Alexendoo
bors Apr 11, 2024
7dca815
Auto merge of #12660 - jqnatividad:fix-various-typos, r=Alexendoo
bors Apr 11, 2024
6b1c828
Auto merge of #12661 - jqnatividad:unsafe_derive_deserialize-why_is_t…
bors Apr 11, 2024
2e989dc
Rollup merge of #123204 - notriddle:notriddle/include-str-span, r=pnk…
matthiaskrgr Apr 12, 2024
0d84f00
Auto merge of #12635 - Alexendoo:doc-check-attributes, r=Jarcho
bors Apr 12, 2024
832fdb6
Auto merge of #12573 - modelflat:recognize-common-prepositions-in-mod…
bors Apr 12, 2024
7063e34
Auto merge of #12094 - yuxqiu:search_is_some, r=xFrednet,ARandomDev99
bors Apr 14, 2024
da0ae33
[`ptr_as_ptr`]: Fix duplicate errors
Luv-Ray Apr 13, 2024
735f2c6
Rustfmt, clippy
compiler-errors Apr 5, 2024
febf858
Remove TypeVariableOriginKind
compiler-errors Mar 24, 2024
1703109
Fix clippy
compiler-errors Apr 14, 2024
b3a82d8
Rollup merge of #123462 - fmease:rn-mod-sep-to-path-sep, r=nnethercote
fmease Apr 15, 2024
ac174ae
Rollup merge of #123926 - compiler-errors:no-ann, r=estebank
fmease Apr 15, 2024
3e11360
Construct `SourceMap` at the same time as `SessionGlobals`.
nnethercote Mar 21, 2024
b64c5f9
Avoid unnecessary `rustc_span::DUMMY_SP` usage.
nnethercote Mar 6, 2024
c0bc812
Always use `ty::` qualifier for `TyKind` enum variants.
nnethercote Mar 6, 2024
0aea3ed
Avoid lots of `hir::HirId{,Map,Set}` qualifiers.
nnethercote Mar 6, 2024
dd0da10
Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obk
bors Apr 16, 2024
ae37fa8
Bump nightly version -> 2024-04-05
flip1995 Apr 16, 2024
f075abb
Auto merge of #12678 - flip1995:bump-nightly, r=flip1995
bors Apr 16, 2024
f5e2501
Auto merge of #12673 - Luv-Ray:fix-ptr-as-ptr-duplicate-errors, r=bly…
bors Apr 16, 2024
1fff3be
Add `cargo dev setup toolchain`
Alexendoo Apr 16, 2024
c4f14ed
Rollup merge of #122811 - nnethercote:mv-SourceMap-init, r=WaffleLapkin
GuillaumeGomez Apr 16, 2024
245fbee
The `multiple_unsafe_ops_per_block` test needs `asm!`
cuviper Apr 16, 2024
432bce6
Rollup merge of #122813 - nnethercote:nicer-quals, r=compiler-errors
matthiaskrgr Apr 17, 2024
1ba7821
Auto merge of #12680 - Alexendoo:cargo-dev-setup-toolchain, r=llogiq
bors Apr 17, 2024
cdd6336
Auto merge of #12682 - cuviper:muopb-asm, r=llogiq
bors Apr 17, 2024
846f6e7
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Apr 18, 2024
fca4e16
Bump nightly version -> 2024-04-18
flip1995 Apr 18, 2024
ca3b393
Auto merge of #12690 - flip1995:rustup, r=flip1995
bors Apr 18, 2024
9028e00
Merge commit 'ca3b393750ee8d870bf3215dcf6509cafa5c0445' into clippy-s…
flip1995 Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/clippy/.github/workflows/remark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
node-version: '18.x'

- name: Install remark
run: npm install remark-cli remark-lint remark-lint-maximum-line-length remark-preset-lint-recommended remark-gfm
run: npm install remark-cli remark-lint remark-lint-maximum-line-length@^3.1.3 remark-preset-lint-recommended remark-gfm

- name: Install mdbook
run: |
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5894,6 +5894,7 @@ Released 2018-09-13
[`allowed-dotfiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-dotfiles
[`allowed-duplicate-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-duplicate-crates
[`allowed-idents-below-min-chars`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-idents-below-min-chars
[`allowed-prefixes`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-prefixes
[`allowed-scripts`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-scripts
[`allowed-wildcard-imports`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-wildcard-imports
[`arithmetic-side-effects-allowed`]: https://doc.rust-lang.org/clippy/lint_configuration.html#arithmetic-side-effects-allowed
Expand Down
28 changes: 19 additions & 9 deletions src/tools/clippy/book/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,27 @@ category.
| `clippy::all` | all lints that are on by default (correctness, suspicious, style, complexity, perf) | **warn/deny** |
| `clippy::correctness` | code that is outright wrong or useless | **deny** |
| `clippy::suspicious` | code that is most likely wrong or useless | **warn** |
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
| `clippy::complexity` | code that does something simple but in a complex way | **warn** |
| `clippy::perf` | code that can be written to run faster | **warn** |
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
| `clippy::pedantic` | lints which are rather strict or might have false positives | allow |
| `clippy::pedantic` | lints which are rather strict or have occasional false positives | allow |
| `clippy::restriction` | lints which prevent the use of language and library features[^restrict] | allow |
| `clippy::nursery` | new lints that are still under development | allow |
| `clippy::cargo` | lints for the cargo manifest | allow | | allow |
| `clippy::cargo` | lints for the cargo manifest | allow |

More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!

The `restriction` category should, *emphatically*, not be enabled as a whole. The contained
lints may lint against perfectly reasonable code, may not have an alternative suggestion,
and may contradict any other lints (including other categories). Lints should be considered
on a case-by-case basis before enabling.

More to come, please [file an
issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
[^restrict]: Some use cases for `restriction` lints include:
- Strict coding styles (e.g. [`clippy::else_if_without_else`]).
- Additional restrictions on CI (e.g. [`clippy::todo`]).
- Preventing panicking in certain functions (e.g. [`clippy::unwrap_used`]).
- Running a lint only on a subset of code (e.g. `#[forbid(clippy::float_arithmetic)]` on a module).

The [lint list](https://rust-lang.github.io/rust-clippy/master/index.html) also
contains "restriction lints", which are for things which are usually not
considered "bad", but may be useful to turn on in specific cases. These should
be used very selectively, if at all.
[`clippy::else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
[`clippy::todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
[`clippy::unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
26 changes: 14 additions & 12 deletions src/tools/clippy/book/src/development/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ because that's clearly a non-descriptive name.
- [Cargo lints](#cargo-lints)
- [Rustfix tests](#rustfix-tests)
- [Testing manually](#testing-manually)
- [Running directly](#running-directly)
- [Lint declaration](#lint-declaration)
- [Lint registration](#lint-registration)
- [Lint passes](#lint-passes)
Expand Down Expand Up @@ -176,23 +175,26 @@ the tests.

Manually testing against an example file can be useful if you have added some
`println!`s and the test suite output becomes unreadable. To try Clippy with
your local modifications, run
your local modifications, run the following from the Clippy directory:

```
```bash
cargo dev lint input.rs
```

from the working copy root. With tests in place, let's have a look at
implementing our lint now.
To run Clippy on an existing project rather than a single file you can use

```bash
cargo dev lint /path/to/project
```

Or set up a rustup toolchain that points to the local Clippy binaries

## Running directly
```bash
cargo dev setup toolchain

While it's easier to just use `cargo dev lint`, it might be desirable to get
`target/release/cargo-clippy` and `target/release/clippy-driver` to work as well in some cases.
By default, they don't work because clippy dynamically links rustc. To help them find rustc,
add the path printed by`rustc --print target-libdir` (ran inside this workspace so that the rustc version matches)
to your library search path.
On linux, this can be done by setting the `LD_LIBRARY_PATH` environment variable to that path.
# Then in `/path/to/project` you can run
cargo +clippy clippy
```

## Lint declaration

Expand Down
26 changes: 26 additions & 0 deletions src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ configuration of Clippy. By default, any configuration will replace the default
* [`min_ident_chars`](https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars)


## `allowed-prefixes`
List of prefixes to allow when determining whether an item's name ends with the module's name.
If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`),
then don't emit a warning.

#### Example

```toml
allowed-prefixes = [ "to", "from" ]
```

#### Noteworthy

- By default, the following prefixes are allowed: `to`, `as`, `into`, `from`, `try_into` and `try_from`
- PascalCase variant is included automatically for each snake_case variant (e.g. if `try_into` is included,
`TryInto` will also be included)
- Use `".."` as part of the list to indicate that the configured values should be appended to the
default configuration of Clippy. By default, any configuration will replace the default value

**Default Value:** `["to", "as", "into", "from", "try_into", "try_from"]`

---
**Affected lints:**
* [`module_name_repetitions`](https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions)


## `allowed-scripts`
The list of unicode scripts allowed to be used in the scope.

Expand Down
22 changes: 22 additions & 0 deletions src/tools/clippy/clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
];
const DEFAULT_DISALLOWED_NAMES: &[&str] = &["foo", "baz", "quux"];
const DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS: &[&str] = &["i", "j", "x", "y", "z", "w", "n"];
const DEFAULT_ALLOWED_PREFIXES: &[&str] = &["to", "as", "into", "from", "try_into", "try_from"];

/// Conf with parse errors
#[derive(Default)]
Expand Down Expand Up @@ -589,6 +590,26 @@ define_Conf! {
/// 2. Paths with any segment that containing the word 'prelude'
/// are already allowed by default.
(allowed_wildcard_imports: FxHashSet<String> = FxHashSet::default()),
/// Lint: MODULE_NAME_REPETITIONS.
///
/// List of prefixes to allow when determining whether an item's name ends with the module's name.
/// If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`),
/// then don't emit a warning.
///
/// #### Example
///
/// ```toml
/// allowed-prefixes = [ "to", "from" ]
/// ```
///
/// #### Noteworthy
///
/// - By default, the following prefixes are allowed: `to`, `as`, `into`, `from`, `try_into` and `try_from`
/// - PascalCase variant is included automatically for each snake_case variant (e.g. if `try_into` is included,
/// `TryInto` will also be included)
/// - Use `".."` as part of the list to indicate that the configured values should be appended to the
/// default configuration of Clippy. By default, any configuration will replace the default value
(allowed_prefixes: Vec<String> = DEFAULT_ALLOWED_PREFIXES.iter().map(ToString::to_string).collect()),
}

/// Search for the configuration file.
Expand Down Expand Up @@ -649,6 +670,7 @@ fn deserialize(file: &SourceFile) -> TryConf {
Ok(mut conf) => {
extend_vec_if_indicator_present(&mut conf.conf.doc_valid_idents, DEFAULT_DOC_VALID_IDENTS);
extend_vec_if_indicator_present(&mut conf.conf.disallowed_names, DEFAULT_DISALLOWED_NAMES);
extend_vec_if_indicator_present(&mut conf.conf.allowed_prefixes, DEFAULT_ALLOWED_PREFIXES);
// TODO: THIS SHOULD BE TESTED, this comment will be gone soon
if conf.conf.allowed_idents_below_min_chars.contains("..") {
conf.conf
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ struct FmtContext {
}

// the "main" function of cargo dev fmt
#[allow(clippy::missing_panics_doc)]
pub fn run(check: bool, verbose: bool) {
fn try_run(context: &FmtContext) -> Result<bool, CliError> {
let mut success = true;
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
unused_lifetimes,
unused_qualifications
)]
#![allow(clippy::missing_panics_doc)]

// The `rustc_driver` crate seems to be required in order to use the `rust_lexer` crate.
#[allow(unused_extern_crates)]
Expand Down
55 changes: 40 additions & 15 deletions src/tools/clippy/clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ fn main() {
}
},
Some(("setup", sub_command)) => match sub_command.subcommand() {
Some(("git-hook", matches)) => {
if matches.get_flag("remove") {
setup::git_hook::remove_hook();
} else {
setup::git_hook::install_hook(matches.get_flag("force-override"));
}
},
Some(("intellij", matches)) => {
if matches.get_flag("remove") {
setup::intellij::remove_rustc_src();
Expand All @@ -57,12 +64,12 @@ fn main() {
);
}
},
Some(("git-hook", matches)) => {
if matches.get_flag("remove") {
setup::git_hook::remove_hook();
} else {
setup::git_hook::install_hook(matches.get_flag("force-override"));
}
Some(("toolchain", matches)) => {
setup::toolchain::create(
matches.get_flag("force"),
matches.get_flag("release"),
matches.get_one::<String>("name").unwrap(),
);
},
Some(("vscode-tasks", matches)) => {
if matches.get_flag("remove") {
Expand Down Expand Up @@ -210,6 +217,19 @@ fn get_clap_config() -> ArgMatches {
.about("Support for setting up your personal development environment")
.arg_required_else_help(true)
.subcommands([
Command::new("git-hook")
.about("Add a pre-commit git hook that formats your code to make it look pretty")
.args([
Arg::new("remove")
.long("remove")
.action(ArgAction::SetTrue)
.help("Remove the pre-commit hook added with 'cargo dev setup git-hook'"),
Arg::new("force-override")
.long("force-override")
.short('f')
.action(ArgAction::SetTrue)
.help("Forces the override of an existing git pre-commit hook"),
]),
Command::new("intellij")
.about("Alter dependencies so Intellij Rust can find rustc internals")
.args([
Expand All @@ -225,18 +245,23 @@ fn get_clap_config() -> ArgMatches {
.conflicts_with("remove")
.required(true),
]),
Command::new("git-hook")
.about("Add a pre-commit git hook that formats your code to make it look pretty")
Command::new("toolchain")
.about("Install a rustup toolchain pointing to the local clippy build")
.args([
Arg::new("remove")
.long("remove")
.action(ArgAction::SetTrue)
.help("Remove the pre-commit hook added with 'cargo dev setup git-hook'"),
Arg::new("force-override")
.long("force-override")
Arg::new("force")
.long("force")
.short('f')
.action(ArgAction::SetTrue)
.help("Forces the override of an existing git pre-commit hook"),
.help("Override an existing toolchain"),
Arg::new("release")
.long("release")
.short('r')
.action(ArgAction::SetTrue)
.help("Point to --release clippy binaries"),
Arg::new("name")
.long("name")
.default_value("clippy")
.help("The name of the created toolchain"),
]),
Command::new("vscode-tasks")
.about("Add several tasks to vscode for formatting, validation and testing")
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl<T> Context for io::Result<T> {
/// # Errors
///
/// This function errors out if the files couldn't be created or written to.
#[allow(clippy::missing_panics_doc)]
pub fn create(
pass: &String,
lint_name: Option<&String>,
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_dev/src/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod git_hook;
pub mod intellij;
pub mod toolchain;
pub mod vscode;

use std::path::Path;
Expand Down
75 changes: 75 additions & 0 deletions src/tools/clippy/clippy_dev/src/setup/toolchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::env::consts::EXE_SUFFIX;
use std::env::current_dir;
use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;

use super::verify_inside_clippy_dir;

pub fn create(force: bool, release: bool, name: &str) {
if !verify_inside_clippy_dir() {
return;
}

let rustup_home = std::env::var("RUSTUP_HOME").unwrap();
let toolchain = std::env::var("RUSTUP_TOOLCHAIN").unwrap();

let src = PathBuf::from_iter([&rustup_home, "toolchains", &toolchain]);
let dest = PathBuf::from_iter([&rustup_home, "toolchains", name]);

if dest.exists() {
if force {
fs::remove_dir_all(&dest).unwrap();
} else {
println!("{} already exists, pass `--force` to override it", dest.display());
return;
}
}

for entry in WalkDir::new(&src) {
let entry = entry.unwrap();
let relative = entry.path().strip_prefix(&src).unwrap();

if relative.starts_with("bin")
&& matches!(
relative.file_stem().and_then(OsStr::to_str),
Some("cargo-clippy" | "clippy-driver")
)
{
continue;
}

let target = dest.join(relative);
if entry.file_type().is_dir() {
fs::create_dir(&target).unwrap();
} else {
fs::hard_link(entry.path(), target).unwrap();
}
}

symlink_bin("cargo-clippy", &dest, release);
symlink_bin("clippy-driver", &dest, release);

println!("Created toolchain {name}, use it in other projects with e.g. `cargo +{name} clippy`");
println!("Note: This will need to be re-run whenever the Clippy `rust-toolchain` changes");
}

fn symlink_bin(bin: &str, dest: &Path, release: bool) {
#[cfg(windows)]
use std::os::windows::fs::symlink_file as symlink;

#[cfg(not(windows))]
use std::os::unix::fs::symlink;

let profile = if release { "release" } else { "debug" };
let file_name = format!("{bin}{EXE_SUFFIX}");

let mut src = current_dir().unwrap();
src.extend(["target", profile, &file_name]);

let mut dest = dest.to_path_buf();
dest.extend(["bin", &file_name]);

symlink(src, dest).unwrap();
}
Loading
Loading