Skip to content

Update Clippy #87152

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 64 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
84c511f
rc_mutex
Jun 2, 2021
c0f3c2f
correct lint
Jun 3, 2021
a5ced1f
rc_mutex use span_lint instead of span_lint_and_sugg
lengyijun Jun 5, 2021
e2ec85c
rc_mutex: add struct test
lengyijun Jun 5, 2021
896c19e
rc_mutex: update doc
lengyijun Jun 5, 2021
f877f54
rc_mutex: fix test
lengyijun Jun 5, 2021
683c557
rc_mutex: add known problems
lengyijun Jun 11, 2021
59cf7e3
Rename all_crate_nums query to crates and remove useless wrapper
bjorn3 Jun 7, 2021
ebe5286
Merge commit '61eb38aeda6cb54b93b872bf503d70084c4d621c' into clippyup
flip1995 Jul 1, 2021
7cd0643
Auto merge of #86782 - flip1995:clippyup, r=Manishearth
bors Jul 2, 2021
b9cc2fe
rc_mutex: known problems
lengyijun Jul 2, 2021
0f662e5
Downgrade nonstandard_macro_braces to nursery
dtolnay Jul 3, 2021
2abeac1
Auto merge of #7424 - dtolnay-contrib:macrobraces, r=llogiq
bors Jul 3, 2021
8420999
Auto merge of #7316 - lengyijun:rc_mutex, r=llogiq
bors Jul 3, 2021
e9a5694
fix doc_markdown false positive
ebobrow Jul 3, 2021
c195db7
Auto merge of #7426 - ebobrow:doc-markdown-fp, r=llogiq
bors Jul 3, 2021
cb4670d
Fix use_self ICE
camsteffen Jul 3, 2021
0a59c24
Auto merge of #7428 - camsteffen:use-self-ice, r=flip1995
bors Jul 3, 2021
1d110f8
Fix emitting in nested (proc_)macros for nonstandard_macro_braces lint
DevinR528 Jul 4, 2021
89f6c4c
allow inference vars in type_implements_trait
nikomatsakis Jul 4, 2021
3cc6778
Auto merge of #7431 - DevinR528:fix-macro-brace, r=llogiq
bors Jul 4, 2021
26e57f0
revert broken formatting
nikomatsakis Jul 4, 2021
59a164e
Add new lint: strlen_on_c_strings
mgacek8 May 18, 2021
64d74df
Auto merge of #7243 - mgacek8:issue7145_strlen_on_c_strings, r=giraffate
bors Jul 5, 2021
eeefbb7
fix false positive (panic message) with assert macro using message pa…
iobtl Jul 6, 2021
28e7699
Auto merge of #7439 - iobtl:assert_msg_panic_fp, r=flip1995
bors Jul 6, 2021
30c5c2f
Add s to non_fmt_panic
rylev Jun 29, 2021
f0f3b3a
Make type_implements_trait not a query
arora-aman Jul 6, 2021
7de1efa
Auto merge of #86920 - JohnTitor:rollup-buvzpkr, r=JohnTitor
bors Jul 7, 2021
3bc5abe
default_numeric_fallback: Fix FP with floating literal
Y-Nak Jul 8, 2021
795868d
Rename run_lints -> lints_enabled
flip1995 Jul 8, 2021
3fc3445
Rework SESSION_GLOBALS API to prevent overwriting it
GuillaumeGomez May 5, 2021
8da39e6
Auto merge of #7448 - flip1995:run_lints-rename, r=llogiq
bors Jul 9, 2021
04aa3f7
`default_numeric_fallback`: Add more tests for floating literal
Y-Nak Jul 9, 2021
5add651
Remove lints_enabled function
flip1995 Jul 9, 2021
d2c8f50
Rename `is_allowed` -> `is_lint_allowed`
flip1995 Jul 9, 2021
cb16543
Auto merge of #7449 - flip1995:remove-lints_enabled, r=camsteffen
bors Jul 9, 2021
dce2740
clippy: allow default_hash_types on bootstrap
camsteffen Jul 8, 2021
075a289
rustc_span: Revert addition of `proc_macro` field to `ExpnKind::Macro`
petrochenkov Jul 10, 2021
f05949f
Add fixed example to unused_unit documentation
flip1995 Jul 13, 2021
94d6be4
Auto merge of #7458 - flip1995:unused_unit-doc, r=giraffate
bors Jul 13, 2021
4e8cd4d
Fix `NumericLiteral::format` that may produce a invalid literal
Y-Nak Jul 13, 2021
3fc8dae
Allow needless_bool in macro
camsteffen Jun 9, 2021
20dbb27
Fix useless_format false positive
camsteffen Jul 4, 2021
e6ab222
Refactor format macro parsing
camsteffen Jul 6, 2021
73ffae6
Reduce redundant code
camsteffen Jul 12, 2021
306f9e8
Split a lint message into help
camsteffen Jul 12, 2021
bf4512e
Auto merge of #7442 - camsteffen:format-args, r=xFrednet
bors Jul 13, 2021
25e4c7d
`default_numeric_fallback`: Add rustfix tests
Y-Nak Jul 13, 2021
8131445
Auto merge of #7446 - Y-Nak:fix-7445, r=xFrednet,flip1995
bors Jul 13, 2021
2fd8dbc
Auto merge of #86827 - camsteffen:hash-lint-resolved, r=oli-obk
bors Jul 13, 2021
251c3b6
fix 5707
lengyijun Jun 11, 2021
1091002
rename possible_borrowed to possible_origin; pass dogfood
lengyijun Jul 14, 2021
f07feca
Auto merge of #7346 - lengyijun:redundant_clone_5707, r=oli-obk
bors Jul 14, 2021
4c398e0
suggest `&mut` for redundant FnMut closures
ebobrow Jul 3, 2021
4acbff9
Auto merge of #7437 - ebobrow:redundant-closure-move, r=flip1995
bors Jul 14, 2021
61e2808
Fixed `branches_sharing_code` FP with block expressions in else
xFrednet Jul 13, 2021
2b193e2
Auto merge of #7462 - xFrednet:7369-branches-sharing-code-else-expr-f…
bors Jul 14, 2021
e575610
redundant_allocation: add Arc; some refractoring.
lengyijun Jun 2, 2021
09f5f15
Auto merge of #7308 - lengyijun:redundant_allocation_arc, r=xFrednet,…
bors Jul 15, 2021
69fbd64
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 15, 2021
43b0121
Bump nightly version -> 2021-07-15
flip1995 Jul 15, 2021
54a20a0
Auto merge of #7468 - flip1995:rustup, r=flip1995
bors Jul 15, 2021
e7bc411
Merge commit '54a20a02ecd0e1352a871aa0990bcc8b8b03173e' into clippyup
flip1995 Jul 15, 2021
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
2 changes: 2 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,7 @@ Released 2018-09-13
[`range_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_step_by_zero
[`range_zip_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_zip_with_len
[`rc_buffer`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer
[`rc_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex
[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
Expand Down Expand Up @@ -2797,6 +2798,7 @@ Released 2018-09-13
[`string_from_utf8_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_from_utf8_as_bytes
[`string_lit_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_as_bytes
[`string_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_to_string
[`strlen_on_c_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#strlen_on_c_strings
[`struct_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#struct_excessive_bools
[`suboptimal_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#suboptimal_flops
[`suspicious_arithmetic_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_arithmetic_impl
Expand Down
5 changes: 2 additions & 3 deletions src/tools/clippy/clippy_lints/src/cargo_common_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use std::path::PathBuf;

use clippy_utils::diagnostics::span_lint;
use clippy_utils::run_lints;
use clippy_utils::{diagnostics::span_lint, is_lint_allowed};
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
Expand Down Expand Up @@ -85,7 +84,7 @@ fn is_empty_vec(value: &[String]) -> bool {

impl LateLintPass<'_> for CargoCommonMetadata {
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) {
if is_lint_allowed(cx, CARGO_COMMON_METADATA, CRATE_HIR_ID) {
return;
}

Expand Down
14 changes: 8 additions & 6 deletions src/tools/clippy/clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then};
use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt};
use clippy_utils::{
both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, is_else_clause,
run_lints, search_same, ContainsName, SpanlessEq, SpanlessHash,
is_lint_allowed, search_same, ContainsName, SpanlessEq, SpanlessHash,
};
use if_chain::if_chain;
use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -120,7 +120,10 @@ declare_clippy_lint! {
///
/// **Why is this bad?** Duplicate code is less maintainable.
///
/// **Known problems:** Hopefully none.
/// **Known problems:**
/// * The lint doesn't check if the moved expressions modify values that are beeing used in
/// the if condition. The suggestion can in that case modify the behavior of the program.
/// See [rust-clippy#7452](https://github.com/rust-lang/rust-clippy/issues/7452)
///
/// **Example:**
/// ```ignore
Expand Down Expand Up @@ -337,8 +340,8 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option<
if block_expr_eq;
if l_stmts.len() == r_stmts.len();
if l_stmts.len() == current_start_eq;
if run_lints(cx, &[IF_SAME_THEN_ELSE], win[0].hir_id);
if run_lints(cx, &[IF_SAME_THEN_ELSE], win[1].hir_id);
if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, win[0].hir_id);
if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, win[1].hir_id);
then {
span_lint_and_note(
cx,
Expand All @@ -358,8 +361,7 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option<
expr_eq &= block_expr_eq;
}

let has_expr = blocks[0].expr.is_some();
if has_expr && !expr_eq {
if !expr_eq {
end_eq = 0;
}

Expand Down
26 changes: 18 additions & 8 deletions src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet;
use clippy_utils::numeric_literal;
use clippy_utils::source::snippet_opt;
use if_chain::if_chain;
use rustc_ast::ast::{LitFloatType, LitIntType, LitKind};
use rustc_errors::Applicability;
Expand Down Expand Up @@ -78,16 +79,25 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
if let Some(ty_bound) = self.ty_bounds.last();
if matches!(lit.node,
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed));
if !ty_bound.is_integral();
if !ty_bound.is_numeric();
then {
let suffix = match lit_ty.kind() {
ty::Int(IntTy::I32) => "i32",
ty::Float(FloatTy::F64) => "f64",
let (suffix, is_float) = match lit_ty.kind() {
ty::Int(IntTy::I32) => ("i32", false),
ty::Float(FloatTy::F64) => ("f64", true),
// Default numeric fallback never results in other types.
_ => return,
};

let sugg = format!("{}_{}", snippet(self.cx, lit.span, ""), suffix);
let src = if let Some(src) = snippet_opt(self.cx, lit.span) {
src
} else {
match lit.node {
LitKind::Int(src, _) => format!("{}", src),
LitKind::Float(src, _) => format!("{}", src),
_ => return,
}
};
let sugg = numeric_literal::format(&src, Some(suffix), is_float);
span_lint_and_sugg(
self.cx,
DEFAULT_NUMERIC_FALLBACK,
Expand Down Expand Up @@ -219,10 +229,10 @@ enum TyBound<'tcx> {
}

impl<'tcx> TyBound<'tcx> {
fn is_integral(self) -> bool {
fn is_numeric(self) -> bool {
match self {
TyBound::Any => true,
TyBound::Ty(t) => t.is_integral(),
TyBound::Ty(t) => t.is_numeric(),
TyBound::Nothing => false,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_context;
use clippy_utils::ty::peel_mid_ty_refs;
use clippy_utils::{get_parent_node, in_macro, is_allowed};
use clippy_utils::{get_parent_node, in_macro, is_lint_allowed};
use rustc_ast::util::parser::PREC_PREFIX;
use rustc_errors::Applicability;
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, UnOp};
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {

match kind {
RefOp::Method(target_mut)
if !is_allowed(cx, EXPLICIT_DEREF_METHODS, expr.hir_id)
if !is_lint_allowed(cx, EXPLICIT_DEREF_METHODS, expr.hir_id)
&& is_linted_explicit_deref_position(parent, expr.hir_id, expr.span) =>
{
self.state = Some((
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_then};
use clippy_utils::paths;
use clippy_utils::ty::{implements_trait, is_copy};
use clippy_utils::{get_trait_def_id, is_allowed, is_automatically_derived, match_def_path};
use clippy_utils::{get_trait_def_id, is_automatically_derived, is_lint_allowed, match_def_path};
use if_chain::if_chain;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor};
Expand Down Expand Up @@ -362,7 +362,7 @@ fn check_unsafe_derive_deserialize<'tcx>(
if let ty::Adt(def, _) = ty.kind();
if let Some(local_def_id) = def.did.as_local();
let adt_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
if !is_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
if !is_lint_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
if cx.tcx.inherent_impls(def.did)
.iter()
.map(|imp_did| item_from_def_id(cx, *imp_did))
Expand Down
9 changes: 6 additions & 3 deletions src/tools/clippy/clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
FootnoteReference(text) | Text(text) => {
let (begin, span) = get_current_span(spans, range.start);
paragraph_span = paragraph_span.with_hi(span.hi());
ticks_unbalanced |= text.contains('`');
ticks_unbalanced |= text.contains('`') && !in_code;
if Some(&text) == in_link.as_ref() || ticks_unbalanced {
// Probably a link of the form `<http://example.com>`
// Which are represented as a link to "http://example.com" with
Expand Down Expand Up @@ -595,7 +595,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
let handler = Handler::with_emitter(false, None, box emitter);
let sess = ParseSess::with_span_handler(handler, sm);

let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code.into()) {
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) {
Ok(p) => p,
Err(errs) => {
for mut err in errs {
Expand Down Expand Up @@ -653,7 +653,10 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
// Because of the global session, we need to create a new session in a different thread with
// the edition we need.
let text = text.to_owned();
if thread::spawn(move || has_needless_main(text, edition)).join().expect("thread::spawn failed") {
if thread::spawn(move || has_needless_main(text, edition))
.join()
.expect("thread::spawn failed")
{
span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest");
}
}
Expand Down
20 changes: 16 additions & 4 deletions src/tools/clippy/clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::higher;
use clippy_utils::higher::VecArgs;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::{implements_trait, type_is_unsafe_function};
use clippy_utils::usage::UsedAfterExprVisitor;
use clippy_utils::{get_enclosing_loop_or_closure, higher};
use clippy_utils::{is_adjusted, iter_input_pats};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{def_id, Expr, ExprKind, Param, PatKind, QPath};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty::{self, ClosureKind, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
Expand Down Expand Up @@ -86,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
}
}

fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
fn check_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Closure(_, decl, eid, _, _) = expr.kind {
let body = cx.tcx.hir().body(eid);
let ex = &body.value;
Expand Down Expand Up @@ -131,7 +132,18 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {

then {
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| {
if let Some(snippet) = snippet_opt(cx, caller.span) {
if let Some(mut snippet) = snippet_opt(cx, caller.span) {
if_chain! {
if let ty::Closure(_, substs) = fn_ty.kind();
if let ClosureKind::FnMut = substs.as_closure().kind();
if UsedAfterExprVisitor::is_found(cx, caller)
|| get_enclosing_loop_or_closure(cx.tcx, expr).is_some();

then {
// Mutable closure is used after current expr; we cannot consume it.
snippet = format!("&mut {}", snippet);
}
}
diag.span_suggestion(
expr.span,
"replace the closure with the function itself",
Expand Down
Loading