Skip to content

Commit

Permalink
Rollup merge of rust-lang#91154 - flip1995:clippyup, r=Manishearth
Browse files Browse the repository at this point in the history
Update Clippy

r? `@Manishearth`

Delayed Clippy sync. I didn't get to it over the weekend..
  • Loading branch information
matthiaskrgr authored Nov 23, 2021
2 parents 5c8ed8f + b95545b commit c9ce710
Show file tree
Hide file tree
Showing 427 changed files with 6,434 additions and 2,490 deletions.
21 changes: 13 additions & 8 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ dependencies = [
"filetime",
"if_chain",
"itertools 0.10.1",
"parking_lot",
"quote",
"regex",
"rustc-workspace-hack",
Expand All @@ -600,6 +601,7 @@ name = "clippy_dev"
version = "0.0.1"
dependencies = [
"bytecount",
"cargo_metadata 0.14.0",
"clap",
"indoc",
"itertools 0.10.1",
Expand Down Expand Up @@ -1713,9 +1715,12 @@ dependencies = [

[[package]]
name = "instant"
version = "0.1.6"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if 1.0.0",
]

[[package]]
name = "itertools"
Expand Down Expand Up @@ -1992,9 +1997,9 @@ version = "0.1.0"

[[package]]
name = "lock_api"
version = "0.4.1"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c"
checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109"
dependencies = [
"scopeguard",
]
Expand Down Expand Up @@ -2511,9 +2516,9 @@ dependencies = [

[[package]]
name = "parking_lot"
version = "0.11.1"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
Expand All @@ -2522,9 +2527,9 @@ dependencies = [

[[package]]
name = "parking_lot_core"
version = "0.8.3"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [
"cfg-if 1.0.0",
"instant",
Expand Down
12 changes: 0 additions & 12 deletions src/tools/clippy/.github/workflows/clippy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v2.3.3

- name: remove toolchain file
run: rm rust-toolchain

- name: rust-toolchain
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: nightly
target: x86_64-unknown-linux-gnu
profile: minimal
components: rustfmt
default: true

# Run
- name: Build
run: cargo build --features deny-warnings
Expand Down
19 changes: 11 additions & 8 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Current beta, release 2021-12-02
[#7560](https://github.com/rust-lang/rust-clippy/pull/7560)
* [`unnecessary_unwrap`]: Now also checks for `expect`s
[#7584](https://github.com/rust-lang/rust-clippy/pull/7584)
* [`disallowed_method`]: Allow adding a reason that will be displayed with the
* [`disallowed_methods`]: Allow adding a reason that will be displayed with the
lint message
[#7621](https://github.com/rust-lang/rust-clippy/pull/7621)
* [`approx_constant`]: Now checks the MSRV for `LOG10_2` and `LOG2_10`
Expand Down Expand Up @@ -174,7 +174,7 @@ Current stable, released 2021-10-21

* [`needless_continue`]: Now also lints in `loop { continue; }` case
[#7477](https://github.com/rust-lang/rust-clippy/pull/7477)
* [`disallowed_type`]: Now also primitive types can be disallowed
* [`disallowed_types`]: Now also primitive types can be disallowed
[#7488](https://github.com/rust-lang/rust-clippy/pull/7488)
* [`manual_swap`]: Now also lints on xor swaps
[#7506](https://github.com/rust-lang/rust-clippy/pull/7506)
Expand Down Expand Up @@ -248,7 +248,7 @@ Released 2021-09-09
[#7403](https://github.com/rust-lang/rust-clippy/pull/7403)
* [`disallowed_script_idents`]
[#7400](https://github.com/rust-lang/rust-clippy/pull/7400)
* [`disallowed_type`]
* [`disallowed_types`]
[#7315](https://github.com/rust-lang/rust-clippy/pull/7315)
* [`missing_enforced_import_renames`]
[#7300](https://github.com/rust-lang/rust-clippy/pull/7300)
Expand Down Expand Up @@ -294,7 +294,7 @@ Released 2021-09-09
[#7379](https://github.com/rust-lang/rust-clippy/pull/7379)
* [`redundant_closure`]: Suggests `&mut` for `FnMut`
[#7437](https://github.com/rust-lang/rust-clippy/pull/7437)
* [`disallowed_method`], [`disallowed_type`]: The configuration values `disallowed-method` and `disallowed-type`
* [`disallowed_methods`], [`disallowed_types`]: The configuration values `disallowed-method` and `disallowed-type`
no longer require fully qualified paths
[#7345](https://github.com/rust-lang/rust-clippy/pull/7345)
* [`zst_offset`]: Fixed lint invocation after it was accidentally suppressed
Expand Down Expand Up @@ -703,7 +703,7 @@ Released 2021-05-06

### Enhancements

* [`disallowed_method`]: Now supports functions in addition to methods
* [`disallowed_methods`]: Now supports functions in addition to methods
[#6674](https://github.com/rust-lang/rust-clippy/pull/6674)
* [`upper_case_acronyms`]: Added a new configuration `upper-case-acronyms-aggressive` to
trigger the lint if there is more than one uppercase character next to each other
Expand Down Expand Up @@ -1044,7 +1044,7 @@ Released 2020-12-31

* [`field_reassign_with_default`] [#5911](https://github.com/rust-lang/rust-clippy/pull/5911)
* [`await_holding_refcell_ref`] [#6029](https://github.com/rust-lang/rust-clippy/pull/6029)
* [`disallowed_method`] [#6081](https://github.com/rust-lang/rust-clippy/pull/6081)
* [`disallowed_methods`] [#6081](https://github.com/rust-lang/rust-clippy/pull/6081)
* [`inline_asm_x86_att_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092)
* [`inline_asm_x86_intel_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092)
* [`from_iter_instead_of_collect`] [#6101](https://github.com/rust-lang/rust-clippy/pull/6101)
Expand Down Expand Up @@ -2821,9 +2821,9 @@ Released 2018-09-13
[`derivable_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
Expand Down Expand Up @@ -2904,6 +2904,7 @@ Released 2018-09-13
[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops
[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping
[`inconsistent_struct_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor
[`index_refutable_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice
[`indexing_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing
[`ineffective_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_bit_mask
[`inefficient_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inefficient_to_string
Expand Down Expand Up @@ -3038,6 +3039,7 @@ Released 2018-09-13
[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
[`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
[`needless_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
[`needless_splitn`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_splitn
[`needless_update`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
[`neg_cmp_op_on_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_cmp_op_on_partial_ord
[`neg_multiply`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_multiply
Expand All @@ -3054,6 +3056,7 @@ Released 2018-09-13
[`nonsensical_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonsensical_open_options
[`nonstandard_macro_braces`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces
[`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
[`octal_escapes`]: https://rust-lang.github.io/rust-clippy/master/index.html#octal_escapes
[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
[`option_as_ref_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ itertools = "0.10"
quote = "1.0"
serde = { version = "1.0", features = ["derive"] }
syn = { version = "1.0", features = ["full"] }
parking_lot = "0.11.2"

[build-dependencies]
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ opener = "0.5"
regex = "1.5"
shell-escape = "0.1"
walkdir = "2.3"
cargo_metadata = "0.14"

[features]
deny-warnings = []
44 changes: 26 additions & 18 deletions src/tools/clippy/clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::clippy_project_root;
use itertools::Itertools;
use shell_escape::escape;
use std::ffi::OsStr;
use std::ffi::{OsStr, OsString};
use std::path::Path;
use std::process::{self, Command};
use std::{fs, io};
Expand Down Expand Up @@ -56,15 +57,22 @@ pub fn run(check: bool, verbose: bool) {
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
success &= cargo_fmt(context, &project_root.join("lintcheck"))?;

for entry in WalkDir::new(project_root.join("tests")) {
let entry = entry?;
let path = entry.path();

if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
continue;
}

success &= rustfmt(context, path)?;
let chunks = WalkDir::new(project_root.join("tests"))
.into_iter()
.filter_map(|entry| {
let entry = entry.expect("failed to find tests");
let path = entry.path();

if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
None
} else {
Some(entry.into_path().into_os_string())
}
})
.chunks(250);

for chunk in &chunks {
success &= rustfmt(context, chunk)?;
}

Ok(success)
Expand Down Expand Up @@ -149,7 +157,7 @@ fn exec(
}

fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
let mut args = vec!["+nightly", "fmt", "--all"];
let mut args = vec!["fmt", "--all"];
if context.check {
args.push("--");
args.push("--check");
Expand All @@ -162,7 +170,7 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
let program = "rustfmt";
let dir = std::env::current_dir()?;
let args = &["+nightly", "--version"];
let args = &["--version"];

if context.verbose {
println!("{}", format_command(&program, &dir, args));
Expand All @@ -185,14 +193,14 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
}
}

fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
let mut args = vec!["+nightly".as_ref(), path.as_os_str()];
fn rustfmt(context: &FmtContext, paths: impl Iterator<Item = OsString>) -> Result<bool, CliError> {
let mut args = Vec::new();
if context.check {
args.push("--check".as_ref());
args.push(OsString::from("--check"));
}
args.extend(paths);

let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
if !success {
eprintln!("rustfmt failed on {}", path.display());
}

Ok(success)
}
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 @@ -7,6 +7,7 @@ use std::path::PathBuf;

pub mod bless;
pub mod fmt;
pub mod lint;
pub mod new_lint;
pub mod serve;
pub mod setup;
Expand Down
20 changes: 20 additions & 0 deletions src/tools/clippy/clippy_dev/src/lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::process::{self, Command};

pub fn run(filename: &str) {
let code = Command::new("cargo")
.args(["run", "--bin", "clippy-driver", "--"])
.args(["-L", "./target/debug"])
.args(["-Z", "no-codegen"])
.args(["--edition", "2021"])
.arg(filename)
.env("__CLIPPY_INTERNAL_TESTS", "true")
.status()
.expect("failed to run cargo")
.code();

if code.is_none() {
eprintln!("Killed by signal");
}

process::exit(code.unwrap_or(1));
}
15 changes: 14 additions & 1 deletion src/tools/clippy/clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![warn(rust_2018_idioms, unused_lifetimes)]

use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use clippy_dev::{bless, fmt, new_lint, serve, setup, update_lints};
use clippy_dev::{bless, fmt, lint, new_lint, serve, setup, update_lints};
fn main() {
let matches = get_clap_config();

Expand Down Expand Up @@ -55,6 +55,10 @@ fn main() {
let lint = matches.value_of("lint");
serve::run(port, lint);
},
("lint", Some(matches)) => {
let filename = matches.value_of("filename").unwrap();
lint::run(filename);
},
_ => {},
}
}
Expand Down Expand Up @@ -219,5 +223,14 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
)
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
)
.subcommand(
SubCommand::with_name("lint")
.about("Manually run clippy on a file")
.arg(
Arg::with_name("filename")
.required(true)
.help("The path to a file to lint"),
),
)
.get_matches()
}
21 changes: 18 additions & 3 deletions src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ fn to_camel_case(name: &str) -> String {
.collect()
}

fn get_stabilisation_version() -> String {
let mut command = cargo_metadata::MetadataCommand::new();
command.no_deps();
if let Ok(metadata) = command.exec() {
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
}
}

String::from("<TODO set version(see doc/adding_lints.md)>")
}

fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
let mut contents = format!(
indoc! {"
Expand Down Expand Up @@ -178,6 +190,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
},
};

let version = get_stabilisation_version();
let lint_name = lint.name;
let category = lint.category;
let name_camel = to_camel_case(lint.name);
Expand Down Expand Up @@ -212,7 +225,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
});

result.push_str(&format!(
indoc! {"
indoc! {r#"
declare_clippy_lint! {{
/// ### What it does
///
Expand All @@ -226,11 +239,13 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
/// ```rust
/// // example code which does not raise clippy warning
/// ```
#[clippy::version = "{version}"]
pub {name_upper},
{category},
\"default lint description\"
"default lint description"
}}
"},
"#},
version = version,
name_upper = name_upper,
category = category,
));
Expand Down
Loading

0 comments on commit c9ce710

Please sign in to comment.