Skip to content
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

Clippyup #97248

Merged
merged 127 commits into from
May 21, 2022
Merged

Clippyup #97248

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
bdc8961
Add version filtering option to the lint list
Serial-ATA Apr 24, 2022
06cc1ab
Move js out to its own file
Serial-ATA Apr 26, 2022
948af01
Don't lint `vec_init_then_push` when further extended
Jarcho Apr 14, 2022
9173780
Make filters implicit; Update symbols
Serial-ATA Apr 29, 2022
d102969
Support negative ints in manual_range_contains
arieluy Apr 29, 2022
6ff77b9
Fix `cast_lossless` to avoid warning on `usize` to `f64` conversion.
sunfishcode May 2, 2022
2c70af3
Only require minor version
Serial-ATA May 3, 2022
dd7bc86
Change input placeholder
Serial-ATA May 5, 2022
f0c2ac8
Bless clippy error msg
nbdd0121 May 5, 2022
7cd86aa
Merge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyup
flip1995 May 5, 2022
ed8458f
(Partially) Revert "HACK: Move buggy lints to nursery"
flip1995 May 5, 2022
6881a5a
Added missing `### What it does`
fedemartinezdev May 5, 2022
0509a96
Auto merge of #8789 - fedemartinezdev:master, r=flip1995
bors May 5, 2022
17bea31
Revert hack fixing #2475 added in commit 034c81b76145a0514916f3471367…
Jarcho May 5, 2022
bf7182c
Auto merge of #8790 - Jarcho:attribute_line, r=flip1995
bors May 5, 2022
4ed52bf
Use CamelCase; Fix filter ranges
Serial-ATA May 5, 2022
5dad517
Auto merge of #8778 - sunfishcode:main, r=giraffate
bors May 6, 2022
677b38c
Suggest -Zunpretty=ast-tree instead of -Zast-json
jyn514 May 6, 2022
2aa63c9
Create RangeBounds struct
arieluy May 6, 2022
bbe6e94
Auto merge of #8792 - jyn514:remove-ast-json, r=flip1995
bors May 6, 2022
1594e98
Auto merge of #8763 - arieluy:manual_range_contains, r=xFrednet
bors May 6, 2022
91a822c
Address `unnecessary_to_owned` false positive
smoelius May 6, 2022
905a951
Pass through extra args in `cargo dev lint`
Alexendoo May 6, 2022
5d0ca74
Resolved conflicts
tamaroning Apr 29, 2022
c09778d
use def_span and def_kind queries instead of calling tcx.hir() methods
kckeiks Apr 29, 2022
43756b6
Auto merge of #8793 - Alexendoo:dev-lint-extra-args, r=xFrednet
bors May 6, 2022
13e8ace
Rollup merge of #96557 - nbdd0121:const, r=oli-obk
GuillaumeGomez May 6, 2022
dd6ee7f
Auto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-ty…
bors May 7, 2022
41c7e4d
Lint for significant drops who may have surprising lifetimes #1
PrestonFrom Feb 18, 2022
8d85889
fix
tamaroning May 7, 2022
9c78883
Auto merge of #8794 - smoelius:fix-8759, r=llogiq
bors May 7, 2022
bca3d8a
Track if a where bound comes from a impl Trait desugar
flip1995 May 5, 2022
03960eb
Replace `#[allow]` with `#[expect]` in Clippy
xFrednet May 7, 2022
6d03789
Auto merge of #94206 - PrestonFrom:significant_drop, r=flip1995
bors May 8, 2022
bdfea1c
Pass msrvs by copy
smoelius May 8, 2022
597f61b
Optionally allow `expect` and `unwrap` in tests
smoelius May 8, 2022
21e4765
Test `expect` attribute for tool lints, clippy edition (RFC 2383)
xFrednet Mar 31, 2022
1d018ce
Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot
bors May 8, 2022
4667198
Auto merge of #8802 - smoelius:allow-expect-unwrap-in-tests, r=llogiq
bors May 8, 2022
670bc53
Auto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiser
bors May 9, 2022
5e4f092
use let chains in bit_mask.rs
Alexendoo May 9, 2022
c9d88ef
Recommend let chains over if_chain in docs
Alexendoo May 9, 2022
47e9afa
fix clippy
SparrowLii May 9, 2022
c3f3c58
Auto merge of #8805 - Alexendoo:let-chain-docs, r=flip1995
bors May 9, 2022
0f1544f
Reduce unnecessary work in `cmp_owned`
Jarcho May 9, 2022
993b401
Don't lint `cmp_owned` when `From::from` results in a copy type.
Jarcho May 9, 2022
aa03344
Auto merge of #8797 - xFrednet:0000-expect-a-playground, r=flip1995
bors May 9, 2022
6edf0b4
Ignore unfulfilled_lint_expectations in metadata collection
Alexendoo May 9, 2022
77effb7
Auto merge of #8809 - Alexendoo:metadata-collection-expect, r=xFrednet
bors May 9, 2022
fe84ff3
New lint: [`derive_partial_eq_without_eq`]
nsunderland1 May 6, 2022
107ee40
update clippy
lcnr Apr 26, 2022
feb6d8c
introduce rc_clone_in_vec_init lint
yonip23 May 8, 2022
1a11a49
Auto merge of #8769 - yonip23:8719, r=xFrednet
bors May 10, 2022
d422baa
Auto merge of #8796 - nsunderland1:master, r=giraffate
bors May 10, 2022
aaf87c3
fix
tamaroning May 10, 2022
1926217
chore
tamaroning May 10, 2022
631b4ee
Fix redundant_allocation warning for Rc<Box<str>>
evantypanski May 10, 2022
f3e01c4
add suggestions to rc_clone_in_vec_init
yonip23 May 10, 2022
554dc41
Fix `match_single_binding` for assign expressions
Serial-ATA Apr 20, 2022
cf8ea64
Introduce EarlyBinder
jackh726 May 8, 2022
ae0216d
Use the traits added to the Rust 2021 Edition prelude
koic May 10, 2022
3182532
Bless clippy.
cjgillot May 11, 2022
6889d09
Auto merge of #8726 - Serial-ATA:issue-8723, r=dswij,xFrednet
bors May 11, 2022
344888a
fix review comments
yonip23 May 11, 2022
a3d1f28
Auto merge of #8818 - koic:use_rust_2021_prelude, r=flip1995
bors May 11, 2022
a791205
fix clippy warning
yonip23 May 11, 2022
9e66f2d
fix
tamaroning May 12, 2022
dc23b5d
fix indentation + test
yonip23 May 12, 2022
8708a26
Some lintcheck cleanup
Alexendoo May 7, 2022
7161a70
Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwco
bors May 12, 2022
0def44a
Catch other thinning allocations using Ty
evantypanski May 12, 2022
ed3744b
inline construct_lint_suggestions
yonip23 May 12, 2022
b54f446
Auto merge of #8799 - Alexendoo:lintcheck-common, r=giraffate
bors May 12, 2022
4e5f69c
Tweak some words improved representation
ydah May 13, 2022
01d75b1
Auto merge of #8825 - ydah:fix_spelling, r=giraffate
bors May 13, 2022
ad7338e
Comment why `hir_ty_to_ty` is safe in `check_ty`
evantypanski May 13, 2022
2038084
Auto merge of #8813 - evantypanski:redundant_alloc_fat_ptr, r=Alexendoo
bors May 13, 2022
b622f56
remove TestItemNamesVisitor
kckeiks May 7, 2022
cc0607a
Add bound_type_of
jackh726 May 8, 2022
6dab55c
Add bound_fn_sig
jackh726 May 8, 2022
1f79a44
Add `duplicate_mod` lint
Alexendoo May 14, 2022
198c70d
Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk
bors May 14, 2022
a30587e
Switch input to `type=number`; Separate version validation out of `by…
Serial-ATA May 15, 2022
c10bfae
Auto merge of #8832 - Alexendoo:duplicate-mod, r=Manishearth
bors May 15, 2022
b81d703
Use early returns
Serial-ATA May 15, 2022
f112e4d
Improve appearance on smaller screens
Serial-ATA May 15, 2022
50eada1
Rename `eval_order_dependence` to `mixed_read_write_in_expression`
Jarcho May 3, 2022
4fd2968
Move `mixed_read_write_in_expression` into `restriction`
Jarcho May 3, 2022
f7378da
Add renamed lints to the changelog link list
Jarcho May 3, 2022
1c0a61e
Auto merge of #8621 - Jarcho:eval_order_dependence_4637, r=Jarcho
bors May 15, 2022
f1574cc
Update `vec_init_then_push` docs
Jarcho Apr 24, 2022
6ec7359
Auto merge of #8699 - Jarcho:vec_init_then_push_7071, r=dswij,xFrednet
bors May 15, 2022
a1632ff
Auto merge of #8761 - tamaroning:fix_8505, r=Jarcho
bors May 16, 2022
0f30866
Add a query for checking whether a function is an intrinsic.
oli-obk May 13, 2022
c649d4e
Fix ICE in `let_unit_value` when calling a static or const callable type
Jarcho May 16, 2022
6e86ab0
Auto merge of #8752 - Serial-ATA:improve-filtering, r=xFrednet
bors May 16, 2022
219d702
Auto merge of #8835 - Jarcho:let_unit_ice, r=llogiq
bors May 16, 2022
d7a6654
Change `Successors` to `impl Iterator<Item = BasicBlock>`
SparrowLii May 17, 2022
d901079
Auto merge of #8814 - yonip23:add-suggestion-to-rc-clone-in-vec-init,…
bors May 17, 2022
7062eb4
Auto merge of #96825 - kckeiks:remove-item-like-visitor-trait, r=cjgi…
bors May 17, 2022
e9f3cdf
Auto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwco
bors May 17, 2022
ae9d727
Rollup merge of #97079 - SparrowLii:successors, r=lcnr
JohnTitor May 17, 2022
acc822a
Auto merge of #97111 - JohnTitor:rollup-x3vjf6u, r=JohnTitor
bors May 17, 2022
b4c3f0f
fix
tamaroning May 17, 2022
bf2e631
Auto merge of #8807 - Jarcho:cmp_owned, r=giraffate
bors May 18, 2022
5647257
Improve "unknown field" error messages
smoelius May 12, 2022
27fec01
Add copy lint name button
Serial-ATA May 18, 2022
b6ad6fc
Auto merge of #8823 - smoelius:unknown-field, r=xFrednet
bors May 18, 2022
01421e0
Auto merge of #96863 - SparrowLii:let, r=michaelwoerister
bors May 18, 2022
8aae26b
`innerHTML` -> `textContent`
Serial-ATA May 18, 2022
e05da56
`textContent` -> `innerHTML`
Serial-ATA May 18, 2022
6f8d18f
Auto merge of #8839 - Serial-ATA:copy-lint-name, r=xFrednet
bors May 18, 2022
db41df1
fix
tamaroning May 19, 2022
b787f4c
Mini changelog update for Rust 1.61.0
xFrednet May 19, 2022
944e1bb
Remove code block from `pub_enum_variant_names`
Serial-ATA May 19, 2022
ea96091
Auto merge of #8838 - tamaroning:fix_dbg, r=Jarcho,xFrednet
bors May 19, 2022
879cd37
Auto merge of #8840 - xFrednet:0000-mini-changelog-update, r=llogiq
bors May 19, 2022
6f26383
Auto merge of #8841 - Serial-ATA:remove-code-block, r=xFrednet
bors May 19, 2022
5730fd4
Lint indirect usages in `disallowed_methods`
Alexendoo May 20, 2022
4e6cf00
Merge remote-tracking branch 'upstream/master' into rustup
xFrednet May 20, 2022
5b72632
move to sus and fix dogfood
xFrednet May 20, 2022
8283238
Update clippy version `0.1.62` -> `0.1.63`
xFrednet May 20, 2022
f26f117
Auto merge of #8852 - Alexendoo:indirect-disallowed-methods, r=Manish…
bors May 20, 2022
7842dbc
Remove duplicated code and ignore deadlock test
xFrednet May 20, 2022
b312ad7
Auto merge of #8856 - xFrednet:rustup, r=Manishearth,Alexendoo
bors May 20, 2022
13cc27b
Merge 'rust-clippy/master' into clippyup
xFrednet May 21, 2022
6e87c24
Fix lint registration
xFrednet May 21, 2022
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
7 changes: 4 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ dependencies = [

[[package]]
name = "clippy"
version = "0.1.62"
version = "0.1.63"
dependencies = [
"clippy_lints",
"clippy_utils",
Expand All @@ -647,6 +647,7 @@ dependencies = [
"serde",
"syn",
"tempfile",
"termize",
"tester",
"tokio",
]
Expand All @@ -667,7 +668,7 @@ dependencies = [

[[package]]
name = "clippy_lints"
version = "0.1.62"
version = "0.1.63"
dependencies = [
"cargo_metadata",
"clippy_utils",
Expand All @@ -688,7 +689,7 @@ dependencies = [

[[package]]
name = "clippy_utils"
version = "0.1.62"
version = "0.1.63"
dependencies = [
"arrayvec",
"if_chain",
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/.github/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rm -rf out/master/ || exit 0
echo "Making the docs for master"
mkdir out/master/
cp util/gh-pages/index.html out/master
cp util/gh-pages/script.js out/master
cp util/gh-pages/lints.json out/master

if [[ -n $TAG_NAME ]]; then
Expand Down
45 changes: 42 additions & 3 deletions src/tools/clippy/CHANGELOG.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ and resolved paths.

[`T-AST`] issues will generally need you to match against a predefined syntax structure.
To figure out how this syntax structure is encoded in the AST, it is recommended to run
`rustc -Z ast-json` on an example of the structure and compare with the [nodes in the AST docs].
`rustc -Z unpretty=ast-tree` on an example of the structure and compare with the [nodes in the AST docs].
Usually the lint will end up to be a nested series of matches and ifs, [like so][deep-nesting].
But we can make it nest-less by using [if_chain] macro, [like this][nest-less].
But we can make it nest-less by using [let chains], [like this][nest-less].

[`E-medium`] issues are generally pretty easy too, though it's recommended you work on an [`good-first-issue`]
first. Sometimes they are only somewhat involved code wise, but not difficult per-se.
Expand All @@ -87,9 +87,9 @@ an AST expression). `match_def_path()` in Clippy's `utils` module can also be us
[`E-medium`]: https://github.com/rust-lang/rust-clippy/labels/E-medium
[`ty`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty
[nodes in the AST docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/
[deep-nesting]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/mem_forget.rs#L29-L43
[if_chain]: https://docs.rs/if_chain/*/if_chain
[nest-less]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/bit_mask.rs#L124-L150
[deep-nesting]: https://github.com/rust-lang/rust-clippy/blob/5e4f0922911536f80d9591180fa604229ac13939/clippy_lints/src/mem_forget.rs#L31-L45
[let chains]: https://github.com/rust-lang/rust/pull/94927
[nest-less]: https://github.com/rust-lang/rust-clippy/blob/5e4f0922911536f80d9591180fa604229ac13939/clippy_lints/src/bit_mask.rs#L133-L159

## Writing code

Expand Down
3 changes: 2 additions & 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.62"
version = "0.1.63"
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 @@ -25,6 +25,7 @@ clippy_lints = { path = "clippy_lints" }
semver = "1.0"
rustc_tools_util = { path = "rustc_tools_util" }
tempfile = { version = "3.2", optional = true }
termize = "0.1"

[dev-dependencies]
compiletest_rs = { version = "0.7.1", features = ["tmp"] }
Expand Down
5 changes: 4 additions & 1 deletion src/tools/clippy/clippy_dev/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn exit_if_err(status: io::Result<ExitStatus>) {
}
}

pub fn run(path: &str) {
pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a str>) {
let is_file = match fs::metadata(path) {
Ok(metadata) => metadata.is_file(),
Err(e) => {
Expand All @@ -30,6 +30,7 @@ pub fn run(path: &str) {
.args(["-Z", "no-codegen"])
.args(["--edition", "2021"])
.arg(path)
.args(args)
.status(),
);
} else {
Expand All @@ -42,6 +43,8 @@ pub fn run(path: &str) {
.expect("failed to create tempdir");

let status = Command::new(cargo_clippy_path())
.arg("clippy")
.args(args)
.current_dir(path)
.env("CARGO_TARGET_DIR", target.as_ref())
.status();
Expand Down
17 changes: 15 additions & 2 deletions src/tools/clippy/clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ fn main() {
},
("lint", Some(matches)) => {
let path = matches.value_of("path").unwrap();
lint::run(path);
let args = matches.values_of("args").into_iter().flatten();
lint::run(path, args);
},
("rename_lint", Some(matches)) => {
let old_name = matches.value_of("old_name").unwrap();
Expand Down Expand Up @@ -123,7 +124,7 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
* the lint count in README.md is correct\n \
* the changelog contains markdown link references at the bottom\n \
* all lint groups include the correct lints\n \
* lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
* lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
* all lints are registered in the lint store",
)
.arg(Arg::with_name("print-only").long("print-only").help(
Expand Down Expand Up @@ -278,11 +279,23 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
Lint a package directory:
cargo dev lint tests/ui-cargo/wildcard_dependencies/fail
cargo dev lint ~/my-project

Run rustfix:
cargo dev lint ~/my-project -- --fix

Set lint levels:
cargo dev lint file.rs -- -W clippy::pedantic
cargo dev lint ~/my-project -- -- -W clippy::pedantic
"})
.arg(
Arg::with_name("path")
.required(true)
.help("The path to a file or package directory to lint"),
)
.arg(
Arg::with_name("args")
.multiple(true)
.help("Pass extra arguments to cargo/clippy-driver"),
),
)
.subcommand(
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn to_camel_case(name: &str) -> String {
.collect()
}

fn get_stabilisation_version() -> String {
fn get_stabilization_version() -> String {
fn parse_manifest(contents: &str) -> Option<String> {
let version = contents
.lines()
Expand Down Expand Up @@ -199,7 +199,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
},
};

let version = get_stabilisation_version();
let version = get_stabilization_version();
let lint_name = lint.name;
let category = lint.category;
let name_camel = to_camel_case(lint.name);
Expand Down
15 changes: 10 additions & 5 deletions src/tools/clippy/clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const GENERATED_FILE_COMMENT: &str = "// This file was generated by `cargo dev u

const DOCS_LINK: &str = "https://rust-lang.github.io/rust-clippy/master/index.html";

#[derive(Clone, Copy, PartialEq)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum UpdateMode {
Check,
Change,
Expand Down Expand Up @@ -66,8 +66,13 @@ fn generate_lint_files(
|res| {
for lint in usable_lints
.iter()
.map(|l| &l.name)
.chain(deprecated_lints.iter().map(|l| &l.name))
.map(|l| &*l.name)
.chain(deprecated_lints.iter().map(|l| &*l.name))
.chain(
renamed_lints
.iter()
.map(|l| l.old_name.strip_prefix("clippy::").unwrap_or(&l.old_name)),
)
.sorted()
{
writeln!(res, "[`{}`]: {}#{}", lint, DOCS_LINK, lint).unwrap();
Expand Down Expand Up @@ -372,7 +377,7 @@ fn exit_with_failure() {
}

/// Lint data parsed from the Clippy source code.
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug)]
struct Lint {
name: String,
group: String,
Expand Down Expand Up @@ -414,7 +419,7 @@ impl Lint {
}
}

#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug)]
struct DeprecatedLint {
name: String,
reason: String,
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.62"
version = "0.1.63"
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: 1 addition & 3 deletions src/tools/clippy/clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ impl ApproxConstant {
let s = s.as_str();
if s.parse::<f64>().is_ok() {
for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS {
if is_approx_const(constant, s, min_digits)
&& msrv.as_ref().map_or(true, |msrv| meets_msrv(self.msrv.as_ref(), msrv))
{
if is_approx_const(constant, s, min_digits) && msrv.map_or(true, |msrv| meets_msrv(self.msrv, msrv)) {
span_lint_and_help(
cx,
APPROX_CONSTANT,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ declare_clippy_lint! {
/// ### Known problems
/// Clippy cannot know for sure if `a op= a op b` should have
/// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore, it suggests both.
/// If `a op= a op b` is really the correct behaviour it should be
/// If `a op= a op b` is really the correct behavior it should be
/// written as `a = a op a op b` as it's less confusing.
///
/// ### Example
Expand Down
23 changes: 6 additions & 17 deletions src/tools/clippy/clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use clippy_utils::msrvs;
use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
use clippy_utils::{extract_msrv_attr, meets_msrv};
use if_chain::if_chain;
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MacArgs, MacArgsEq, MetaItemKind, NestedMetaItem};
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
use rustc_errors::Applicability;
use rustc_hir::{
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
Expand Down Expand Up @@ -586,21 +586,10 @@ impl EarlyLintPass for EarlyAttributes {

fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
for attr in &item.attrs {
let attr_item = if let AttrKind::Normal(ref attr, _) = attr.kind {
attr
} else {
return;
};

if attr.style == AttrStyle::Outer {
if let MacArgs::Eq(_, MacArgsEq::Ast(expr)) = &attr_item.args
&& !matches!(expr.kind, rustc_ast::ExprKind::Lit(..)) {
return;
}
if attr_item.args.inner_tokens().is_empty() || !is_present_in_source(cx, attr.span) {
return;
}

if matches!(attr.kind, AttrKind::Normal(..))
&& attr.style == AttrStyle::Outer
&& is_present_in_source(cx, attr.span)
{
let begin_of_attr_to_item = Span::new(attr.span.lo(), item.span.lo(), item.span.ctxt(), item.span.parent());
let end_of_attr_to_item = Span::new(attr.span.hi(), item.span.lo(), item.span.ctxt(), item.span.parent());

Expand All @@ -624,7 +613,7 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It

fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: Option<RustcVersion>) {
if_chain! {
if meets_msrv(msrv.as_ref(), &msrvs::TOOL_ATTRIBUTES);
if meets_msrv(msrv, msrvs::TOOL_ATTRIBUTES);
// check cfg_attr
if attr.has_name(sym::cfg_attr);
if let Some(items) = attr.meta_item_list();
Expand Down
40 changes: 20 additions & 20 deletions src/tools/clippy/clippy_lints/src/bit_mask.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clippy_utils::consts::{constant, Constant};
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
use clippy_utils::sugg::Sugg;
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind};
Expand Down Expand Up @@ -130,32 +129,33 @@ impl<'tcx> LateLintPass<'tcx> for BitMask {
}
}
}
if_chain! {
if let ExprKind::Binary(op, left, right) = &e.kind;
if BinOpKind::Eq == op.node;
if let ExprKind::Binary(op1, left1, right1) = &left.kind;
if BinOpKind::BitAnd == op1.node;
if let ExprKind::Lit(lit) = &right1.kind;
if let LitKind::Int(n, _) = lit.node;
if let ExprKind::Lit(lit1) = &right.kind;
if let LitKind::Int(0, _) = lit1.node;
if n.leading_zeros() == n.count_zeros();
if n > u128::from(self.verbose_bit_mask_threshold);
then {
span_lint_and_then(cx,
VERBOSE_BIT_MASK,
e.span,
"bit mask could be simplified with a call to `trailing_zeros`",
|diag| {

if let ExprKind::Binary(op, left, right) = &e.kind
&& BinOpKind::Eq == op.node
&& let ExprKind::Binary(op1, left1, right1) = &left.kind
&& BinOpKind::BitAnd == op1.node
&& let ExprKind::Lit(lit) = &right1.kind
&& let LitKind::Int(n, _) = lit.node
&& let ExprKind::Lit(lit1) = &right.kind
&& let LitKind::Int(0, _) = lit1.node
&& n.leading_zeros() == n.count_zeros()
&& n > u128::from(self.verbose_bit_mask_threshold)
{
span_lint_and_then(
cx,
VERBOSE_BIT_MASK,
e.span,
"bit mask could be simplified with a call to `trailing_zeros`",
|diag| {
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
diag.span_suggestion(
e.span,
"try",
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),
Applicability::MaybeIncorrect,
);
});
}
},
);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
}
for (n, expr) in self.terminals.iter().enumerate() {
if eq_expr_value(self.cx, e, expr) {
#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
return Ok(Bool::Term(n as u8));
}

Expand All @@ -149,15 +149,15 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
if eq_expr_value(self.cx, e_lhs, expr_lhs);
if eq_expr_value(self.cx, e_rhs, expr_rhs);
then {
#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
}
}
}
let n = self.terminals.len();
self.terminals.push(e);
if n < 32 {
#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
Ok(Bool::Term(n as u8))
} else {
Err("too many literals".to_owned())
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/borrow_as_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl BorrowAsPtr {

impl<'tcx> LateLintPass<'tcx> for BorrowAsPtr {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if !meets_msrv(self.msrv.as_ref(), &msrvs::BORROW_AS_PTR) {
if !meets_msrv(self.msrv, msrvs::BORROW_AS_PTR) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub(super) fn check(
cast_expr: &Expr<'_>,
cast_from: Ty<'_>,
cast_to: Ty<'_>,
msrv: &Option<RustcVersion>,
msrv: Option<RustcVersion>,
) {
if_chain! {
if meets_msrv(msrv.as_ref(), &msrvs::UNSIGNED_ABS);
if meets_msrv(msrv, msrvs::UNSIGNED_ABS);
if cast_from.is_integral();
if cast_to.is_integral();
if cast_from.is_signed();
Expand Down
Loading