Skip to content

Commit

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

r? `@Manishearth`
  • Loading branch information
bors committed Jun 2, 2023
2 parents 427a453 + e6dc0ef commit 6a5e3de
Show file tree
Hide file tree
Showing 114 changed files with 2,971 additions and 654 deletions.
23 changes: 0 additions & 23 deletions .github/ISSUE_TEMPLATE/new_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,6 @@ body:
description: What does this lint do?
validations:
required: true
- type: input
id: lint-name
attributes:
label: Lint Name
description: Please provide the lint name.
- type: dropdown
id: category
attributes:
label: Category
description: >
What category should this lint go into? If you're unsure you can select
multiple categories. You can find a category description in the
`README`.
multiple: true
options:
- correctness
- suspicious
- style
- complexity
- perf
- pedantic
- restriction
- cargo
- type: textarea
id: advantage
attributes:
Expand Down
130 changes: 129 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,132 @@ document.

## Unreleased / Beta / In Rust Nightly

[149392b0...master](https://github.com/rust-lang/rust-clippy/compare/149392b0...master)
[83e42a23...master](https://github.com/rust-lang/rust-clippy/compare/83e42a23...master)

## Rust 1.70

Current beta, released 2023-06-01

[149392b0...83e42a23](https://github.com/rust-lang/rust-clippy/compare/149392b0...83e42a23)

### New Lints

* [`large_futures`]
[#10414](https://github.com/rust-lang/rust-clippy/pull/10414)
* [`missing_assert_message`]
[#10362](https://github.com/rust-lang/rust-clippy/pull/10362)
* [`clear_with_drain`]
[#10528](https://github.com/rust-lang/rust-clippy/pull/10528)
* [`redundant_async_block`]
[#10448](https://github.com/rust-lang/rust-clippy/pull/10448)
* [`collection_is_never_read`]
[#10415](https://github.com/rust-lang/rust-clippy/pull/10415)
* [`let_with_type_underscore`]
[#10467](https://github.com/rust-lang/rust-clippy/pull/10467)
* [`tests_outside_test_module`]
[#10543](https://github.com/rust-lang/rust-clippy/pull/10543)
* [`allow_attributes`]
[#10481](https://github.com/rust-lang/rust-clippy/pull/10481)
* [`suspicious_doc_comments`]
[#10497](https://github.com/rust-lang/rust-clippy/pull/10497)
* [`unnecessary_box_returns`]
[#9102](https://github.com/rust-lang/rust-clippy/pull/9102)
* [`manual_main_separator_str`]
[#10483](https://github.com/rust-lang/rust-clippy/pull/10483)
* [`unnecessary_struct_initialization`]
[#10489](https://github.com/rust-lang/rust-clippy/pull/10489)
* [`manual_slice_size_calculation`]
[#10601](https://github.com/rust-lang/rust-clippy/pull/10601)
* [`lines_filter_map_ok`]
[#10534](https://github.com/rust-lang/rust-clippy/pull/10534)

### Moves and Deprecations

* Moved [`let_underscore_untyped`] to `restriction`
[#10442](https://github.com/rust-lang/rust-clippy/pull/10442)

### Enhancements

* [`extra_unused_type_parameters`]: No longer lints on public items if `avoid-breaking-exported-api` is set
[#10536](https://github.com/rust-lang/rust-clippy/pull/10536)
* [`len_without_is_empty`]: Now also detects `async` functions
[#10359](https://github.com/rust-lang/rust-clippy/pull/10359)
* [`arithmetic_side_effects`]: Now correctly handles divisions and modulo expressions if the right-hand-side
is unknown
[#10585](https://github.com/rust-lang/rust-clippy/pull/10585)
* [`nonminimal_bool`]: No longer ignores `#[allow]` attributes
[#10588](https://github.com/rust-lang/rust-clippy/pull/10588)
* [`uninit_vec`], [`uninit_assumed_init`]: Now uses a better heuristic
[#10520](https://github.com/rust-lang/rust-clippy/pull/10520)
* [`ifs_same_cond`]: Now also detects immutable method calls.
[#10350](https://github.com/rust-lang/rust-clippy/pull/10350)
* [`arithmetic_side_effects`]: No longer lints on right or left shifts with constant integers, as the
compiler warns about them
[#10309](https://github.com/rust-lang/rust-clippy/pull/10309)
* [`items_after_statements`]: `#[allow(items_after_statements)]` now works on items
[#10542](https://github.com/rust-lang/rust-clippy/pull/10542)
* [`significant_drop_tightening`]: Was optimized
[#10533](https://github.com/rust-lang/rust-clippy/pull/10533)

### False Positive Fixes

* [`single_component_path_imports`]: No longer lints if the import is used relative to `self`
[#10566](https://github.com/rust-lang/rust-clippy/pull/10566)
* [`derivable_impls`]: No longer suggests deriving `Default` on generics with implicit arguments
[#10399](https://github.com/rust-lang/rust-clippy/pull/10399)
* [`let_unit_value`]: No longer lints if the expression contains an `await`
[#10439](https://github.com/rust-lang/rust-clippy/pull/10439)
* [`double_must_use`]: Now ignores `async` functions
[#10589](https://github.com/rust-lang/rust-clippy/pull/10589)
* [`manual_clamp`]: No longer lints in constant context
[#10479](https://github.com/rust-lang/rust-clippy/pull/10479)
* [`almost_swapped`]: Now ignores external macros
[#10502](https://github.com/rust-lang/rust-clippy/pull/10502)
* [`nonminimal_bool`]: Now ignores macros
[#10527](https://github.com/rust-lang/rust-clippy/pull/10527)
* [`needless_return`]: No longer lints match statements with incompatible branches
[#10593](https://github.com/rust-lang/rust-clippy/pull/10593)
* [`use_self`]: Do not suggest using `Self` in const generic parameters
[#10375](https://github.com/rust-lang/rust-clippy/pull/10375)
* [`mem_replace_option_with_none`]: No longer lints on field expressions
[#10594](https://github.com/rust-lang/rust-clippy/pull/10594)
* [`items_after_statements`]: No longer lints on times from macros
[#10542](https://github.com/rust-lang/rust-clippy/pull/10542)
* [`print_literal`], [`write_literal`]: No longer lint strings coming from the `file!()` macro
[#10573](https://github.com/rust-lang/rust-clippy/pull/10573)
* [`uninit_vec`], [`uninit_assumed_init`]: Now check the types inside arrays and tuples
[#10553](https://github.com/rust-lang/rust-clippy/pull/10553)
* [`almost_swapped`]: No longer lints if a variable is assigned to itself
[#10499](https://github.com/rust-lang/rust-clippy/pull/10499)
* [`missing_docs_in_private_items`]: No longer lints on public items
[#10324](https://github.com/rust-lang/rust-clippy/pull/10324)

### Suggestion Fixes/Improvements

* [`extra_unused_type_parameters`]: The suggestion is now machine applicable
[#10536](https://github.com/rust-lang/rust-clippy/pull/10536)
* [`match_single_binding`]: Now adds a semicolon after the suggestion
[#10470](https://github.com/rust-lang/rust-clippy/pull/10470)
* [`missing_const_for_fn`]: Now includes a note if the change could break compatibility
[#10618](https://github.com/rust-lang/rust-clippy/pull/10618)
* [`cast_possible_truncation`]: Corrected suggestion for float and wildcard casts
[#10496](https://github.com/rust-lang/rust-clippy/pull/10496)
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now includes parentheses when they are required
[#10454](https://github.com/rust-lang/rust-clippy/pull/10454)

### ICE Fixes

* [`needless_borrow`]: No longer panics on ambiguous projections
[#10403](https://github.com/rust-lang/rust-clippy/pull/10403)
* [`multiple_unsafe_ops_per_block`]: Fix ICE when calling a function-like object in an unsafe block
[#10405](https://github.com/rust-lang/rust-clippy/pull/10405)

### Others

* `clippy-driver` now searches parent directories for `clippy.toml` files
[#10592](https://github.com/rust-lang/rust-clippy/pull/10592)
* Fixed a deserialization error for the `array-size-threshold` config value
[#10423](https://github.com/rust-lang/rust-clippy/pull/10423)

## Rust 1.69

Expand Down Expand Up @@ -4838,6 +4963,7 @@ Released 2018-09-13
[`missing_docs_in_private_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items
[`missing_enforced_import_renames`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_renames
[`missing_errors_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc
[`missing_fields_in_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_fields_in_debug
[`missing_inline_in_public_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_inline_in_public_items
[`missing_panics_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc
[`missing_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
Expand Down Expand Up @@ -4874,6 +5000,7 @@ Released 2018-09-13
[`needless_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
[`needless_continue`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_continue
[`needless_doctest_main`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main
[`needless_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_else
[`needless_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each
[`needless_late_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_late_init
[`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
Expand Down Expand Up @@ -4949,6 +5076,7 @@ Released 2018-09-13
[`println_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#println_empty_string
[`ptr_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
[`ptr_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr
[`ptr_cast_constness`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness
[`ptr_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq
[`ptr_offset_with_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names
Expand Down
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.71"
version = "0.1.72"
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 Expand Up @@ -30,16 +30,11 @@ termize = "0.1"
compiletest_rs = { version = "0.10", features = ["tmp"] }
tester = "0.9"
regex = "1.5"
toml = "0.5"
toml = "0.7.3"
walkdir = "2.3"
# This is used by the `collect-metadata` alias.
filetime = "0.2"

# A noop dependency that changes in the Rust repository, it's a bit of a hack.
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
# for more information.
rustc-workspace-hack = "1.0"

# UI test dependencies
clap = { version = "4.1.4", features = ["derive"] }
clippy_utils = { path = "clippy_utils" }
Expand Down
10 changes: 8 additions & 2 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

> **Note:** The configuration file is unstable and may be deprecated in the future.
Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a
basic `variable = value` mapping e.g.
Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`, which is searched for in:

1. The directory specified by the `CLIPPY_CONF_DIR` environment variable, or
2. The directory specified by the
[CARGO_MANIFEST_DIR](https://doc.rust-lang.org/cargo/reference/environment-variables.html) environment variable, or
3. The current directory.

It contains a basic `variable = value` mapping e.g.

```toml
avoid-breaking-exported-api = false
Expand Down
10 changes: 8 additions & 2 deletions book/src/development/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,14 @@ Before submitting your PR make sure you followed all the basic requirements:

## Adding configuration to a lint

Clippy supports the configuration of lints values using a `clippy.toml` file in
the workspace directory. Adding a configuration to a lint can be useful for
Clippy supports the configuration of lints values using a `clippy.toml` file which is searched for in:

1. The directory specified by the `CLIPPY_CONF_DIR` environment variable, or
2. The directory specified by the
[CARGO_MANIFEST_DIR](https://doc.rust-lang.org/cargo/reference/environment-variables.html) environment variable, or
3. The current directory.

Adding a configuration to a lint can be useful for
thresholds or to constrain some behavior that can be seen as a false positive
for some users. Adding a configuration is done in the following steps:

Expand Down
4 changes: 3 additions & 1 deletion clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use clap::{Arg, ArgAction, ArgMatches, Command};
use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints};
use indoc::indoc;
use std::convert::Infallible;

fn main() {
let matches = get_clap_config();
Expand Down Expand Up @@ -180,7 +181,8 @@ fn get_clap_config() -> ArgMatches {
.short('n')
.long("name")
.help("Name of the new lint in snake case, ex: fn_too_long")
.required(true),
.required(true)
.value_parser(|name: &str| Ok::<_, Infallible>(name.replace('-', "_"))),
Arg::new("category")
.short('c')
.long("category")
Expand Down
10 changes: 4 additions & 6 deletions 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.71"
version = "0.1.72"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand All @@ -20,15 +20,13 @@ quine-mc_cluskey = "0.2"
regex-syntax = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", optional = true }
tempfile = { version = "3.2", optional = true }
toml = "0.5"
tempfile = { version = "3.3.0", optional = true }
toml = "0.7.3"
unicode-normalization = "0.1"
unicode-script = { version = "0.5", default-features = false }
semver = "1.0"
rustc-semver = "1.1"
# NOTE: cargo requires serde feat in its url dep
# see <https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864>
url = { version = "2.2", features = ["serde"] }
url = "2.2"

[features]
deny-warnings = ["clippy_utils/deny-warnings"]
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/allow_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ declare_clippy_lint! {
/// a.len()
/// }
/// ```
#[clippy::version = "1.69.0"]
#[clippy::version = "1.70.0"]
pub ALLOW_ATTRIBUTES,
restriction,
"`#[allow]` will not trigger if a warning isn't found. `#[expect]` triggers if there are no warnings."
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
NonminimalBoolVisitor { cx }.visit_body(body);
}
}

struct NonminimalBoolVisitor<'a, 'tcx> {
cx: &'a LateContext<'tcx>,
}
Expand Down Expand Up @@ -473,6 +472,10 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
self.bool_expr(e);
},
ExprKind::Unary(UnOp::Not, inner) => {
if let ExprKind::Unary(UnOp::Not, ex) = inner.kind &&
!self.cx.typeck_results().node_types()[ex.hir_id].is_bool() {
return;
}
if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() {
self.bool_expr(e);
}
Expand Down
33 changes: 32 additions & 1 deletion clippy_lints/src/casts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod fn_to_numeric_cast;
mod fn_to_numeric_cast_any;
mod fn_to_numeric_cast_with_truncation;
mod ptr_as_ptr;
mod ptr_cast_constness;
mod unnecessary_cast;
mod utils;

Expand Down Expand Up @@ -363,7 +364,7 @@ declare_clippy_lint! {
/// namely `*const T` to `*const U` and `*mut T` to `*mut U`.
///
/// ### Why is this bad?
/// Though `as` casts between raw pointers is not terrible, `pointer::cast` is safer because
/// Though `as` casts between raw pointers are not terrible, `pointer::cast` is safer because
/// it cannot accidentally change the pointer's mutability nor cast the pointer to other types like `usize`.
///
/// ### Example
Expand All @@ -386,6 +387,34 @@ declare_clippy_lint! {
"casting using `as` from and to raw pointers that doesn't change its mutability, where `pointer::cast` could take the place of `as`"
}

declare_clippy_lint! {
/// ### What it does
/// Checks for `as` casts between raw pointers which change its constness, namely `*const T` to
/// `*mut T` and `*mut T` to `*const T`.
///
/// ### Why is this bad?
/// Though `as` casts between raw pointers are not terrible, `pointer::cast_mut` and
/// `pointer::cast_const` are safer because they cannot accidentally cast the pointer to another
/// type.
///
/// ### Example
/// ```rust
/// let ptr: *const u32 = &42_u32;
/// let mut_ptr = ptr as *mut u32;
/// let ptr = mut_ptr as *const u32;
/// ```
/// Use instead:
/// ```rust
/// let ptr: *const u32 = &42_u32;
/// let mut_ptr = ptr.cast_mut();
/// let ptr = mut_ptr.cast_const();
/// ```
#[clippy::version = "1.71.0"]
pub PTR_CAST_CONSTNESS,
pedantic,
"casting using `as` from and to raw pointers to change constness when specialized methods apply"
}

declare_clippy_lint! {
/// ### What it does
/// Checks for casts from an enum type to an integral type which will definitely truncate the
Expand Down Expand Up @@ -652,6 +681,7 @@ impl_lint_pass!(Casts => [
FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
CHAR_LIT_AS_U8,
PTR_AS_PTR,
PTR_CAST_CONSTNESS,
CAST_ENUM_TRUNCATION,
CAST_ENUM_CONSTRUCTOR,
CAST_ABS_TO_UNSIGNED,
Expand Down Expand Up @@ -685,6 +715,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
return;
}
cast_slice_from_raw_parts::check(cx, expr, cast_expr, cast_to, &self.msrv);
ptr_cast_constness::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv);
as_ptr_cast_mut::check(cx, expr, cast_expr, cast_to);
fn_to_numeric_cast_any::check(cx, expr, cast_expr, cast_from, cast_to);
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);
Expand Down
Loading

0 comments on commit 6a5e3de

Please sign in to comment.