Skip to content

Commit

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

r? `@Manishearth`
  • Loading branch information
bors committed May 5, 2023
2 parents f9a6b71 + b53c1bb commit 963e5c0
Show file tree
Hide file tree
Showing 153 changed files with 2,230 additions and 444 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"

[[package]]
name = "clippy"
version = "0.1.70"
version = "0.1.71"
dependencies = [
"clap 4.2.1",
"clippy_lints",
Expand Down Expand Up @@ -619,7 +619,7 @@ dependencies = [

[[package]]
name = "clippy_lints"
version = "0.1.70"
version = "0.1.71"
dependencies = [
"arrayvec",
"cargo_metadata 0.15.3",
Expand All @@ -643,7 +643,7 @@ dependencies = [

[[package]]
name = "clippy_utils"
version = "0.1.70"
version = "0.1.71"
dependencies = [
"arrayvec",
"if_chain",
Expand Down Expand Up @@ -969,7 +969,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"

[[package]]
name = "declare_clippy_lint"
version = "0.1.70"
version = "0.1.71"
dependencies = [
"itertools",
"quote",
Expand Down
6 changes: 6 additions & 0 deletions src/tools/clippy/.github/workflows/remark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jobs:
- name: Check *.md files
run: git ls-files -z '*.md' | xargs -0 -n 1 -I {} ./node_modules/.bin/remark {} -u lint -f > /dev/null

- name: Linkcheck book
run: |
rustup toolchain install nightly --component rust-docs
curl https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh -o linkcheck.sh
sh linkcheck.sh clippy --path ./book
- name: Build mdbook
run: mdbook build book

Expand Down
25 changes: 14 additions & 11 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Current stable, released 2023-04-20

### Enhancements

* [`arithmetic_side_effects`]: No longer lints, if safe constant values are used.
* [`arithmetic_side_effects`]: No longer lints if safe constant values are used.
[#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
* [`needless_lifetimes`]: Now works in local macros
[#10257](https://github.com/rust-lang/rust-clippy/pull/10257)
Expand All @@ -60,39 +60,39 @@ Current stable, released 2023-04-20

### False Positive Fixes

* [`explicit_auto_deref`]: Now considers projections, when determining if auto deref is applicable
* [`explicit_auto_deref`]: Now considers projections when determining if auto deref is applicable
[#10386](https://github.com/rust-lang/rust-clippy/pull/10386)
* [`manual_let_else`]: Now considers side effects of branches, before linting
* [`manual_let_else`]: Now considers side effects of branches before linting
[#10336](https://github.com/rust-lang/rust-clippy/pull/10336)
* [`uninlined_format_args`]: No longer lints for arguments with generic parameters
[#10343](https://github.com/rust-lang/rust-clippy/pull/10343)
* [`needless_lifetimes`]: No longer lints signatures in macros, if the lifetime is a metavariable
* [`needless_lifetimes`]: No longer lints signatures in macros if the lifetime is a metavariable
[#10380](https://github.com/rust-lang/rust-clippy/pull/10380)
* [`len_without_is_empty`]: No longer lints, if `len` as a non-default signature
* [`len_without_is_empty`]: No longer lints if `len` as a non-default signature
[#10255](https://github.com/rust-lang/rust-clippy/pull/10255)
* [`unusual_byte_groupings`]: Relaxed the required restrictions for specific sizes, to reduce false
* [`unusual_byte_groupings`]: Relaxed the required restrictions for specific sizes to reduce false
positives
[#10353](https://github.com/rust-lang/rust-clippy/pull/10353)
* [`manual_let_else`]: No longer lints `if-else` blocks if they can divergent
[#10332](https://github.com/rust-lang/rust-clippy/pull/10332)
* [`expect_used`], [`unwrap_used`], [`dbg_macro`], [`print_stdout`], [`print_stderr`]: No longer lint
in test functions, if `allow-expect-in-tests` is set
in test functions if `allow-expect-in-tests` is set
[#10391](https://github.com/rust-lang/rust-clippy/pull/10391)
* [`unnecessary_safety_comment`]: No longer lints code inside macros
[#10106](https://github.com/rust-lang/rust-clippy/pull/10106)
* [`never_loop`]: No longer lints, for statements following break statements for outer blocks.
* [`never_loop`]: No longer lints statements following break statements for outer blocks.
[#10311](https://github.com/rust-lang/rust-clippy/pull/10311)

### Suggestion Fixes/Improvements

* [`box_default`]: The suggestion now includes the type for trait objects, when needed
* [`box_default`]: The suggestion now includes the type for trait objects when needed
[#10382](https://github.com/rust-lang/rust-clippy/pull/10382)
* [`cast_possible_truncation`]: Now suggests using `try_from` or allowing the lint
[#10038](https://github.com/rust-lang/rust-clippy/pull/10038)
* [`invalid_regex`]: Regex errors for non-literals or regular strings containing escape sequences will
now show the complete error
[#10231](https://github.com/rust-lang/rust-clippy/pull/10231)
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now works, if the base type is borrowed
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now works if the base type is borrowed
[#10193](https://github.com/rust-lang/rust-clippy/pull/10193)
* [`needless_return`]: Now removes all semicolons on the same line
[#10187](https://github.com/rust-lang/rust-clippy/pull/10187)
Expand All @@ -113,7 +113,7 @@ Current stable, released 2023-04-20

### ICE Fixes

* [`needless_pass_by_value`]: Fixed an ICE, caused by how late bounds were handled
* [`needless_pass_by_value`]: Fixed an ICE caused by how late bounds were handled
[#10328](https://github.com/rust-lang/rust-clippy/pull/10328)
* [`needless_borrow`]: No longer panics on ambiguous projections
[#10403](https://github.com/rust-lang/rust-clippy/pull/10403)
Expand Down Expand Up @@ -4582,6 +4582,7 @@ Released 2018-09-13
[`debug_assert_with_mut_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#debug_assert_with_mut_call
[`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation
[`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
[`default_constructed_unit_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs
[`default_instead_of_iter_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_instead_of_iter_empty
[`default_numeric_fallback`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
[`default_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access
Expand Down Expand Up @@ -4797,6 +4798,7 @@ Released 2018-09-13
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
[`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or
[`manual_while_let_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_while_let_some
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
[`map_collect_result_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_collect_result_unit
Expand Down Expand Up @@ -4864,6 +4866,7 @@ Released 2018-09-13
[`needless_arbitrary_self_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_arbitrary_self_type
[`needless_bitwise_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bitwise_bool
[`needless_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool
[`needless_bool_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool_assign
[`needless_borrow`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
[`needless_borrowed_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrowed_reference
[`needless_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.70"
version = "0.1.71"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ cargo clippy

#### Automatically applying Clippy suggestions

Clippy can automatically apply some lint suggestions, just like the compiler.
Clippy can automatically apply some lint suggestions, just like the compiler. Note that `--fix` implies
`--all-targets`, so it can fix as much code as it can.

```terminal
cargo clippy --fix
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/book/src/development/lint_passes.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ questions already, but the parser is okay with it. This is what we
mean when we say `EarlyLintPass` deals with only syntax on the AST level.

Alternatively, think of the `foo_functions` lint we mentioned in
define new lints chapter.
define new lints <!-- FIXME: add link --> chapter.

We want the `foo_functions` lint to detect functions with `foo` as their name.
Writing a lint that only checks for the name of a function means that we only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ whether the pattern matched.
## Pattern syntax

The following examples demonstate the pattern syntax:
The following examples demonstrate the pattern syntax:


#### Any (`_`)
Expand Down
18 changes: 18 additions & 0 deletions src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Please use that command to update the file and do not edit it by hand.
| [msrv](#msrv) | `None` |
| [cognitive-complexity-threshold](#cognitive-complexity-threshold) | `25` |
| [disallowed-names](#disallowed-names) | `["foo", "baz", "quux"]` |
| [semicolon-inside-block-ignore-singleline](#semicolon-inside-block-ignore-singleline) | `false` |
| [semicolon-outside-block-ignore-multiline](#semicolon-outside-block-ignore-multiline) | `false` |
| [doc-valid-idents](#doc-valid-idents) | `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS", "WebGL", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]` |
| [too-many-arguments-threshold](#too-many-arguments-threshold) | `7` |
| [type-complexity-threshold](#type-complexity-threshold) | `250` |
Expand Down Expand Up @@ -203,6 +205,22 @@ default configuration of Clippy. By default, any configuration will replace the
* [disallowed_names](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names)


### semicolon-inside-block-ignore-singleline
Whether to lint only if it's multiline.

**Default Value:** `false` (`bool`)

* [semicolon_inside_block](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_inside_block)


### semicolon-outside-block-ignore-multiline
Whether to lint only if it's singleline.

**Default Value:** `false` (`bool`)

* [semicolon_outside_block](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block)


### doc-valid-idents
The list of words this lint should not consider as identifiers needing ticks. The value
`".."` can be used as part of the list to indicate, that the configured values should be appended to the
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/book/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ fn main() {

### Automatically applying Clippy suggestions

Clippy can automatically apply some lint suggestions, just like the compiler.
Clippy can automatically apply some lint suggestions, just like the compiler. Note that `--fix` implies
`--all-targets`, so it can fix as much code as it can.

```terminal
cargo clippy --fix
Expand Down
8 changes: 3 additions & 5 deletions src/tools/clippy/clippy_dev/src/dogfood.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::clippy_project_root;
use crate::{clippy_project_root, exit_if_err};
use std::process::Command;

/// # Panics
Expand All @@ -10,7 +10,7 @@ pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) {
cmd.current_dir(clippy_project_root())
.args(["test", "--test", "dogfood"])
.args(["--features", "internal"])
.args(["--", "dogfood_clippy"]);
.args(["--", "dogfood_clippy", "--nocapture"]);

let mut dogfood_args = Vec::new();
if fix {
Expand All @@ -27,7 +27,5 @@ pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) {

cmd.env("__CLIPPY_DOGFOOD_ARGS", dogfood_args.join(" "));

let output = cmd.output().expect("failed to run command");

println!("{}", String::from_utf8_lossy(&output.stdout));
exit_if_err(cmd.status());
}
13 changes: 13 additions & 0 deletions src/tools/clippy/clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
extern crate rustc_driver;
extern crate rustc_lexer;

use std::io;
use std::path::PathBuf;
use std::process::{self, ExitStatus};

pub mod bless;
pub mod dogfood;
Expand Down Expand Up @@ -58,3 +60,14 @@ pub fn clippy_project_root() -> PathBuf {
}
panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");
}

pub fn exit_if_err(status: io::Result<ExitStatus>) {
match status.expect("failed to run command").code() {
Some(0) => {},
Some(n) => process::exit(n),
None => {
eprintln!("Killed by signal");
process::exit(1);
},
}
}
17 changes: 3 additions & 14 deletions src/tools/clippy/clippy_dev/src/lint.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
use crate::cargo_clippy_path;
use std::process::{self, Command, ExitStatus};
use std::{fs, io};

fn exit_if_err(status: io::Result<ExitStatus>) {
match status.expect("failed to run command").code() {
Some(0) => {},
Some(n) => process::exit(n),
None => {
eprintln!("Killed by signal");
process::exit(1);
},
}
}
use crate::{cargo_clippy_path, exit_if_err};
use std::fs;
use std::process::{self, Command};

pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
let is_file = match fs::metadata(path) {
Expand Down
54 changes: 0 additions & 54 deletions src/tools/clippy/clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,6 @@ pub enum UpdateMode {
pub fn update(update_mode: UpdateMode) {
let (lints, deprecated_lints, renamed_lints) = gather_all();
generate_lint_files(update_mode, &lints, &deprecated_lints, &renamed_lints);
remove_old_files(update_mode);
}

/// Remove files no longer needed after <https://github.com/rust-lang/rust-clippy/pull/9541>
/// that may be reintroduced unintentionally
///
/// FIXME: This is a temporary measure that should be removed when there are no more PRs that
/// include the stray files
fn remove_old_files(update_mode: UpdateMode) {
let mut failed = false;
let mut remove_file = |path: &Path| match update_mode {
UpdateMode::Check => {
if path.exists() {
failed = true;
println!("unexpected file: {}", path.display());
}
},
UpdateMode::Change => {
if fs::remove_file(path).is_ok() {
println!("removed file: {}", path.display());
}
},
};

let files = [
"clippy_lints/src/lib.register_all.rs",
"clippy_lints/src/lib.register_cargo.rs",
"clippy_lints/src/lib.register_complexity.rs",
"clippy_lints/src/lib.register_correctness.rs",
"clippy_lints/src/lib.register_internal.rs",
"clippy_lints/src/lib.register_lints.rs",
"clippy_lints/src/lib.register_nursery.rs",
"clippy_lints/src/lib.register_pedantic.rs",
"clippy_lints/src/lib.register_perf.rs",
"clippy_lints/src/lib.register_restriction.rs",
"clippy_lints/src/lib.register_style.rs",
"clippy_lints/src/lib.register_suspicious.rs",
"src/docs.rs",
];

for file in files {
remove_file(Path::new(file));
}

if let Ok(docs_dir) = fs::read_dir("src/docs") {
for doc_file in docs_dir {
let path = doc_file.unwrap().path();
remove_file(&path);
}
}

if failed {
exit_with_failure();
}
}

fn generate_lint_files(
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
version = "0.1.70"
version = "0.1.71"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down
4 changes: 3 additions & 1 deletion src/tools/clippy/clippy_lints/src/allow_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use ast::AttrStyle;
use clippy_utils::diagnostics::span_lint_and_sugg;
use rustc_ast as ast;
use rustc_errors::Applicability;
use rustc_lint::{LateContext, LateLintPass};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
Expand Down Expand Up @@ -51,6 +52,7 @@ impl LateLintPass<'_> for AllowAttribute {
// Separate each crate's features.
fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) {
if_chain! {
if !in_external_macro(cx.sess(), attr.span);
if cx.tcx.features().lint_reasons;
if let AttrStyle::Outer = attr.style;
if let Some(ident) = attr.ident();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/casts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ declare_clippy_lint! {
#[clippy::version = "1.66.0"]
pub AS_PTR_CAST_MUT,
nursery,
"casting the result of the `&self`-taking `as_ptr` to a mutabe pointer"
"casting the result of the `&self`-taking `as_ptr` to a mutable pointer"
}

declare_clippy_lint! {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ fn lint_unnecessary_cast(

fn get_numeric_literal<'e>(expr: &'e Expr<'e>) -> Option<&'e Lit> {
match expr.kind {
ExprKind::Lit(ref lit) => Some(lit),
ExprKind::Lit(lit) => Some(lit),
ExprKind::Unary(UnOp::Neg, e) => {
if let ExprKind::Lit(ref lit) = e.kind {
if let ExprKind::Lit(lit) = e.kind {
Some(lit)
} else {
None
Expand Down
Loading

0 comments on commit 963e5c0

Please sign in to comment.