Skip to content

Commit

Permalink
Merge commit '81f37a8150fc86f8de00e6947e86d2b69291906a' into clippyup
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed Nov 23, 2021
2 parents 7c4be43 + 81f37a8 commit 1ee5aa4
Show file tree
Hide file tree
Showing 426 changed files with 6,421 additions and 2,482 deletions.
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
5 changes: 5 additions & 0 deletions src/tools/clippy/clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static DEC_CLIPPY_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
r#"(?x)
declare_clippy_lint!\s*[\{(]
(?:\s+///.*)*
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
(?P<cat>[a-z_]+)\s*,\s*
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
Expand All @@ -31,6 +32,7 @@ static DEC_DEPRECATED_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
r#"(?x)
declare_deprecated_lint!\s*[{(]\s*
(?:\s+///.*)*
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
"#,
Expand Down Expand Up @@ -495,20 +497,23 @@ fn test_parse_contents() {
let result: Vec<Lint> = parse_contents(
r#"
declare_clippy_lint! {
#[clippy::version = "Hello Clippy!"]
pub PTR_ARG,
style,
"really long \
text"
}
declare_clippy_lint!{
#[clippy::version = "Test version"]
pub DOC_MARKDOWN,
pedantic,
"single line"
}
/// some doc comment
declare_deprecated_lint! {
#[clippy::version = "I'm a version"]
pub SHOULD_ASSERT_EQ,
"`assert!()` will be more flexible with RFC 2011"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ declare_clippy_lint! {
/// if vec.len() <= 0 {}
/// if 100 > i32::MAX {}
/// ```
#[clippy::version = "pre 1.29.0"]
pub ABSURD_EXTREME_COMPARISONS,
correctness,
"a comparison with a maximum or minimum value that is always true or false"
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ declare_clippy_lint! {
/// let x = std::f32::consts::PI;
/// let y = std::f64::consts::FRAC_1_PI;
/// ```
#[clippy::version = "pre 1.29.0"]
pub APPROX_CONSTANT,
correctness,
"the approximate of a known float constant (in `std::fXX::consts`)"
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare_clippy_lint! {
/// # let a = 0;
/// a + 1;
/// ```
#[clippy::version = "pre 1.29.0"]
pub INTEGER_ARITHMETIC,
restriction,
"any integer arithmetic expression which could overflow or panic"
Expand All @@ -43,6 +44,7 @@ declare_clippy_lint! {
/// # let a = 0.0;
/// a + 1.0;
/// ```
#[clippy::version = "pre 1.29.0"]
pub FLOAT_ARITHMETIC,
restriction,
"any floating-point arithmetic statement"
Expand Down
Loading

0 comments on commit 1ee5aa4

Please sign in to comment.