Skip to content

Clippy subtree update #119013

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

Merged
merged 85 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
e3a1555
Stabilize C string literals
jmillikin Nov 1, 2023
2d9fc6d
implement unoptimized code logic for [`infinite_loops`]
J-ZhengLi Nov 17, 2023
4de845e
[`missing_asserts_for_indexing`]: accept len equality checks
y21 Nov 18, 2023
3e9a6d1
stop warning never-returning calls
J-ZhengLi Nov 21, 2023
0d26f91
eliminate the second `visit` to save a bit performance.
J-ZhengLi Nov 27, 2023
758d0e8
change name to [`infinite_loop`];
J-ZhengLi Nov 28, 2023
fff7aa0
expending lint [`blocks_in_if_conditions`] to check match expr as well
J-ZhengLi Nov 22, 2023
40b558a
rename [`blocks_in_if_conditions`] to [`blocks_in_conditions`];
J-ZhengLi Nov 30, 2023
6275e77
Do not check twice whether `qpath` is a `QPath::TypeRelative` variant
samueltardieu Nov 30, 2023
512f302
needless_borrows_for_generic_args: Handle when field operand impl Drop
Enselic Dec 1, 2023
3a76090
Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstrieb
bors Dec 1, 2023
5049415
new lint: `repeat_vec_with_capacity`
y21 Oct 2, 2023
76eb781
use `iter::repeat_with` in suggestion and add examples
y21 Dec 1, 2023
c9a43b1
Merge commit 'f0cdee4a3f094416189261481eae374b76792af1' into clippy-s…
flip1995 Dec 1, 2023
5ac76ac
Auto merge of #11597 - y21:repeat_vec_with_capacity, r=dswij
bors Dec 1, 2023
ee83760
Auto merge of #11837 - y21:issue11835, r=dswij
bors Dec 1, 2023
dc702e3
Rename `*note_without_error` as `*note`.
nnethercote Nov 30, 2023
8dab738
Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_…
nnethercote Nov 30, 2023
30f8e87
Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compile…
bors Dec 2, 2023
c586717
Auto merge of #118507 - flip1995:clippy-subtree-sync, r=matthiaskrgr
bors Dec 2, 2023
1e67f6c
Tolerate hidden, binary files in tests/
pgerber Dec 2, 2023
75bdbfc
Auto merge of #11853 - J-ZhengLi:issue11814, r=llogiq
bors Dec 2, 2023
31aa0b2
Auto merge of #11899 - samueltardieu:redundant-if, r=llogiq
bors Dec 2, 2023
da27c97
Auto merge of #11905 - pgerber:tests, r=dswij
bors Dec 2, 2023
6d40b10
Add a function to check whether binary oprands are nontrivial
cocodery Dec 2, 2023
af1b58f
Update regex-syntax to support new word boundry assertions
pgerber Dec 2, 2023
8eea8b1
fix: handle `std::ptr::null{_mut}`
KisaragiEffective Dec 3, 2023
7ffe1ff
Parse a pattern with no arm
Nadrieril Nov 27, 2023
a3ce379
docs(explicit_write): add missing backtick to complete code snippet
KisaragiEffective Dec 3, 2023
8977423
Rewrite logic of `has_nontrivial_oprand`.
cocodery Dec 4, 2023
b4e3b85
Merge Async and Gen into CoroutineKind
eholk Nov 30, 2023
45be5dd
Option<CoroutineKind>
eholk Dec 1, 2023
c9eb8c9
Remove bad merge
eholk Dec 4, 2023
594a5f1
Update doctest
eholk Dec 5, 2023
5f191ce
Fix build
eholk Dec 5, 2023
2e3c031
Rename `has_nontrivial_oprand` to `is_operator_overrided`
cocodery Dec 5, 2023
ebb0ff6
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Dec 5, 2023
9c3492c
Bump nightly version -> 2023-12-05
flip1995 Dec 5, 2023
a7acfa2
Run sanity check for integration tests first
flip1995 Dec 5, 2023
8851621
Auto merge of #11929 - flip1995:rustup, r=flip1995
bors Dec 5, 2023
8fc8aa9
Auto merge of #11904 - pgerber:regex, r=xFrednet
bors Dec 5, 2023
42b017d
Auto merge of #11920 - KisaragiEffective:patch-2, r=xFrednet
bors Dec 5, 2023
4a56563
Auto merge of #11900 - Enselic:needless-borrow-drop, r=Manishearth
bors Dec 5, 2023
ee2354b
Add check for unary-operator
cocodery Dec 6, 2023
a2ea760
Drop clippy::vtable_address_comparisons
Urgau Nov 9, 2023
2793e8d
Auto merge of #11913 - KisaragiEffective:fix/ptr-as-ptr-with-null, r=…
bors Dec 6, 2023
56d20c2
Fix nits and add test for `unnecessary_operation`
cocodery Dec 8, 2023
1c8cbe7
Auto merge of #11907 - cocodery:issue11885, r=y21,xFrednet
bors Dec 8, 2023
cdfa38a
new lint: `uninhabited_reference`
samueltardieu Nov 26, 2023
f39d18b
Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-er…
bors Dec 8, 2023
1512d37
coro_kind -> coroutine_kind
compiler-errors Dec 5, 2023
62f7337
Make some matches exhaustive to avoid bugs, fix tools
compiler-errors Dec 5, 2023
0252580
Auto merge of #118420 - compiler-errors:async-gen, r=eholk
bors Dec 8, 2023
9083b52
Check $CARGO before $PATH
workingjubilee Dec 9, 2023
87aed03
Auto merge of #11944 - workingjubilee:env-lookup-for-cargo, r=Jarcho
bors Dec 10, 2023
0109fa6
remove redundant imports
surechen Nov 10, 2023
7825200
fix clippy
fee1-dead Dec 10, 2023
d347d6f
Add `blyxyas` to `users_on_vacation`
blyxyas Dec 10, 2023
252103b
Auto merge of #11949 - blyxyas:on-vacation, r=Jarcho
bors Dec 10, 2023
184845f
Fix `is_from_proc_macro` patterns
Jarcho Sep 19, 2023
f3f2f17
Delay several `is_from_proc_macro` checks
Jarcho Sep 19, 2023
e35acc2
Add spacing information to delimiters.
nnethercote Oct 12, 2023
3813a7b
Auto merge of #11538 - Jarcho:proc_mac, r=dswij
bors Dec 11, 2023
2a1645d
Auto merge of #11878 - samueltardieu:uninhabited_reference, r=flip1995
bors Dec 11, 2023
1f9b674
Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, r=…
bors Dec 11, 2023
c8213a4
Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=david…
bors Dec 11, 2023
27c5b21
Fix binder handling in `unnecessary_to_owned`
Jarcho Dec 11, 2023
19f5b85
Add `write_and_append` lint
GuillaumeGomez Dec 1, 2023
5accd51
Add ui test for `write_and_append` lint
GuillaumeGomez Dec 1, 2023
ded94ec
Update CHANGELOG to add `write_and_append` lint
GuillaumeGomez Dec 1, 2023
52deee2
Auto merge of #11902 - GuillaumeGomez:write-and-append, r=llogiq
bors Dec 12, 2023
fe37cc1
Move some methods from `tcx.hir()` to `tcx`
zetanumbers Dec 1, 2023
884bec3
emit lints in `check_crate_post` for useless_vec
ericwu17 Nov 28, 2023
2e96c74
Auto merge of #11829 - J-ZhengLi:issue11438, r=matthiaskrgr
bors Dec 12, 2023
c19508b
Auto merge of #11895 - ericwu2003:useless_vec-FP, r=blyxyas
bors Dec 12, 2023
1f2ca81
[`doc_markdown`] Recognize words followed by empty parenthesis `()` f…
intgr Dec 12, 2023
20de341
Uplift TypeAndMut
compiler-errors Dec 12, 2023
1839b79
Auto merge of #11956 - intgr:doc_markdown-include-function-parenthesi…
bors Dec 13, 2023
29bdc8b
Auto merge of #11953 - Jarcho:issue_11952, r=Alexendoo
bors Dec 13, 2023
f90e8ef
Rollup merge of #118888 - compiler-errors:uplift-more-things, r=jackh726
matthiaskrgr Dec 15, 2023
80ccd63
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Dec 16, 2023
71f48ee
Bump nightly version -> 2023-12-16
flip1995 Dec 16, 2023
a859e5c
Auto merge of #11971 - flip1995:rustup, r=flip1995
bors Dec 16, 2023
61f4a73
Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyup
flip1995 Dec 16, 2023
b92ab50
Update Cargo.lock
flip1995 Dec 16, 2023
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
8 changes: 7 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ dependencies = [
"itertools",
"quine-mc_cluskey",
"regex",
"regex-syntax 0.7.2",
"regex-syntax 0.8.2",
"rustc-semver",
"semver",
"serde",
Expand Down Expand Up @@ -3195,6 +3195,12 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"

[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"

[[package]]
name = "remote-test-client"
version = "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/.github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ jobs:
max-parallel: 6
matrix:
integration:
- 'matthiaskrgr/clippy_ci_panic_test'
- 'rust-lang/cargo'
- 'rust-lang/chalk'
- 'rust-lang/rustfmt'
Expand All @@ -220,7 +221,6 @@ jobs:
- 'rust-itertools/itertools'
- 'rust-lang-nursery/failure'
- 'rust-lang/log'
- 'matthiaskrgr/clippy_ci_panic_test'

runs-on: ubuntu-latest

Expand Down
5 changes: 5 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4946,6 +4946,7 @@ Released 2018-09-13
[`blanket_clippy_restriction_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#blanket_clippy_restriction_lints
[`block_in_if_condition_expr`]: https://rust-lang.github.io/rust-clippy/master/index.html#block_in_if_condition_expr
[`block_in_if_condition_stmt`]: https://rust-lang.github.io/rust-clippy/master/index.html#block_in_if_condition_stmt
[`blocks_in_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
[`bool_assert_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
Expand Down Expand Up @@ -5145,9 +5146,11 @@ Released 2018-09-13
[`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
[`ineffective_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_open_options
[`inefficient_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inefficient_to_string
[`infallible_destructuring_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#infallible_destructuring_match
[`infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#infinite_iter
[`infinite_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#infinite_loop
[`inherent_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string
[`inherent_to_string_shadow_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string_shadow_display
[`init_numbered_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#init_numbered_fields
Expand Down Expand Up @@ -5462,6 +5465,7 @@ Released 2018-09-13
[`ref_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_patterns
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once
[`repeat_vec_with_capacity`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_vec_with_capacity
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
[`reserve_after_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#reserve_after_initialization
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
Expand Down Expand Up @@ -5582,6 +5586,7 @@ Released 2018-09-13
[`undropped_manually_drops`]: https://rust-lang.github.io/rust-clippy/master/index.html#undropped_manually_drops
[`unicode_not_nfc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unicode_not_nfc
[`unimplemented`]: https://rust-lang.github.io/rust-clippy/master/index.html#unimplemented
[`uninhabited_references`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninhabited_references
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
[`uninit_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_vec
[`uninlined_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
Expand Down
10 changes: 7 additions & 3 deletions src/tools/clippy/clippy_dev/src/lint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{cargo_clippy_path, exit_if_err};
use std::fs;
use std::process::{self, Command};
use std::{env, fs};

pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
let is_file = match fs::metadata(path) {
Expand All @@ -13,7 +13,7 @@ pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {

if is_file {
exit_if_err(
Command::new("cargo")
Command::new(env::var("CARGO").unwrap_or("cargo".into()))
.args(["run", "--bin", "clippy-driver", "--"])
.args(["-L", "./target/debug"])
.args(["-Z", "no-codegen"])
Expand All @@ -23,7 +23,11 @@ pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
.status(),
);
} else {
exit_if_err(Command::new("cargo").arg("build").status());
exit_if_err(
Command::new(env::var("CARGO").unwrap_or("cargo".into()))
.arg("build")
.status(),
);

let status = Command::new(cargo_clippy_path())
.arg("clippy")
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_dev/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::ffi::OsStr;
use std::num::ParseIntError;
use std::path::Path;
use std::process::Command;
use std::thread;
use std::time::{Duration, SystemTime};
use std::{env, thread};

/// # Panics
///
Expand All @@ -16,7 +16,7 @@ pub fn run(port: u16, lint: Option<&String>) -> ! {

loop {
if mtime("util/gh-pages/lints.json") < mtime("clippy_lints/src") {
Command::new("cargo")
Command::new(env::var("CARGO").unwrap_or("cargo".into()))
.arg("collect-metadata")
.spawn()
.unwrap()
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
Expand Up @@ -16,7 +16,7 @@ clippy_utils = { path = "../clippy_utils" }
declare_clippy_lint = { path = "../declare_clippy_lint" }
itertools = "0.11"
quine-mc_cluskey = "0.2"
regex-syntax = "0.7"
regex-syntax = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", optional = true }
tempfile = { version = "3.3.0", optional = true }
Expand Down
9 changes: 4 additions & 5 deletions src/tools/clippy/clippy_lints/src/as_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ declare_lint_pass!(AsConversions => [AS_CONVERSIONS]);

impl<'tcx> LateLintPass<'tcx> for AsConversions {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
if in_external_macro(cx.sess(), expr.span) || is_from_proc_macro(cx, expr) {
return;
}

if let ExprKind::Cast(_, _) = expr.kind {
if let ExprKind::Cast(_, _) = expr.kind
&& !in_external_macro(cx.sess(), expr.span)
&& !is_from_proc_macro(cx, expr)
{
span_lint_and_help(
cx,
AS_CONVERSIONS,
Expand Down
137 changes: 137 additions & 0 deletions src/tools/clippy/clippy_lints/src/blocks_in_conditions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
use clippy_utils::source::snippet_block_with_applicability;
use clippy_utils::ty::implements_trait;
use clippy_utils::visitors::{for_each_expr, Descend};
use clippy_utils::{get_parent_expr, higher};
use core::ops::ControlFlow;
use rustc_errors::Applicability;
use rustc_hir::{BlockCheckMode, Expr, ExprKind, MatchSource};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass;
use rustc_span::sym;

declare_clippy_lint! {
/// ### What it does
/// Checks for `if` conditions that use blocks containing an
/// expression, statements or conditions that use closures with blocks.
///
/// ### Why is this bad?
/// Style, using blocks in the condition makes it hard to read.
///
/// ### Examples
/// ```no_run
/// # fn somefunc() -> bool { true };
/// if { true } { /* ... */ }
///
/// if { let x = somefunc(); x } { /* ... */ }
/// ```
///
/// Use instead:
/// ```no_run
/// # fn somefunc() -> bool { true };
/// if true { /* ... */ }
///
/// let res = { let x = somefunc(); x };
/// if res { /* ... */ }
/// ```
#[clippy::version = "1.45.0"]
pub BLOCKS_IN_CONDITIONS,
style,
"useless or complex blocks that can be eliminated in conditions"
}

declare_lint_pass!(BlocksInConditions => [BLOCKS_IN_CONDITIONS]);

const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition";

impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if in_external_macro(cx.sess(), expr.span) {
return;
}

let Some((cond, keyword, desc)) = higher::If::hir(expr)
.map(|hif| (hif.cond, "if", "an `if` condition"))
.or(if let ExprKind::Match(match_ex, _, MatchSource::Normal) = expr.kind {
Some((match_ex, "match", "a `match` scrutinee"))
} else {
None
})
else {
return;
};
let complex_block_message = &format!(
"in {desc}, avoid complex blocks or closures with blocks; \
instead, move the block or closure higher and bind it with a `let`",
);

if let ExprKind::Block(block, _) = &cond.kind {
if block.rules == BlockCheckMode::DefaultBlock {
if block.stmts.is_empty() {
if let Some(ex) = &block.expr {
// don't dig into the expression here, just suggest that they remove
// the block
if expr.span.from_expansion() || ex.span.from_expansion() {
return;
}
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
cx,
BLOCKS_IN_CONDITIONS,
cond.span,
BRACED_EXPR_MESSAGE,
"try",
snippet_block_with_applicability(cx, ex.span, "..", Some(expr.span), &mut applicability)
.to_string(),
applicability,
);
}
} else {
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
if span.from_expansion() || expr.span.from_expansion() {
return;
}
// move block higher
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
cx,
BLOCKS_IN_CONDITIONS,
expr.span.with_hi(cond.span.hi()),
complex_block_message,
"try",
format!(
"let res = {}; {keyword} res",
snippet_block_with_applicability(cx, block.span, "..", Some(expr.span), &mut applicability),
),
applicability,
);
}
}
} else {
let _: Option<!> = for_each_expr(cond, |e| {
if let ExprKind::Closure(closure) = e.kind {
// do not lint if the closure is called using an iterator (see #1141)
if let Some(parent) = get_parent_expr(cx, e)
&& let ExprKind::MethodCall(_, self_arg, _, _) = &parent.kind
&& let caller = cx.typeck_results().expr_ty(self_arg)
&& let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator)
&& implements_trait(cx, caller, iter_id, &[])
{
return ControlFlow::Continue(Descend::No);
}

let body = cx.tcx.hir().body(closure.body);
let ex = &body.value;
if let ExprKind::Block(block, _) = ex.kind {
if !body.value.span.from_expansion() && !block.stmts.is_empty() {
span_lint(cx, BLOCKS_IN_CONDITIONS, ex.span, complex_block_message);
return ControlFlow::Continue(Descend::No);
}
}
}
ControlFlow::Continue(Descend::Yes)
});
}
}
}
Loading